home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / vir_real / veos / part07 < prev    next >
Encoding:
Text File  |  1993-06-20  |  85.8 KB  |  3,338 lines

  1. Path: wupost!uunet!decwrl!vixie!vixie!not-for-mail
  2. From: voodoo@hitl.washington.edu (Geoffery Coco)
  3. Newsgroups: comp.sources.unix
  4. Subject: v26i190: veos-2.0 - The Virtual Environment Operating Shell, V2.0, Part07/16
  5. Date: 25 Apr 1993 23:15:09 -0700
  6. Organization: Vixie Home Computing
  7. Lines: 3325
  8. Sender: vixie@vix.com
  9. Approved: paul@vix.com
  10. Message-ID: <1rfuld$5nm@efficacy.home.vix.com>
  11. NNTP-Posting-Host: efficacy.home.vix.com
  12.  
  13. Submitted-By: voodoo@hitl.washington.edu (Geoffery Coco)
  14. Posting-Number: Volume 26, Issue 190
  15. Archive-Name: veos-2.0/part07
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 7 (of 16)."
  24. # Contents:  kernel_private/src/fern/fe_int.lsp
  25. #   kernel_private/src/talk/socket.c
  26. #   src/kernel_current/fern/fe_int.lsp src/xlisp/xcore/c/xlobj.c
  27. #   src/xlisp/xcore/c/xlstr.c
  28. # Wrapped by vixie@efficacy.home.vix.com on Sun Apr 25 23:10:38 1993
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'kernel_private/src/fern/fe_int.lsp' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'kernel_private/src/fern/fe_int.lsp'\"
  32. else
  33. echo shar: Extracting \"'kernel_private/src/fern/fe_int.lsp'\" \(16110 characters\)
  34. sed "s/^X//" >'kernel_private/src/fern/fe_int.lsp' <<'END_OF_FILE'
  35. X;;-----------------------------------------------------------
  36. X;; file: fe_int.lsp
  37. X;;
  38. X;; FERN is the Fractal Entity Relativity Node.
  39. X;; Part of the FE component of the Fern System.
  40. X;;
  41. X;; creation: March 28, 1992
  42. X;;
  43. X;; by Geoffrey P. Coco at the HITLab, Seattle
  44. X;;-----------------------------------------------------------
  45. X
  46. X
  47. X;;-----------------------------------------------------------
  48. X;; Copyright (C) 1992  Geoffrey P. Coco,
  49. X;; Human Interface Technology Lab, Seattle
  50. X;;-----------------------------------------------------------
  51. X
  52. X
  53. X;;===========================================================
  54. X;;              Internal
  55. X;;===========================================================
  56. X
  57. X(defun fe-put.int (int)
  58. X  (vput int '((~ "perc"
  59. X         @
  60. X         @
  61. X         > @) **)))
  62. X
  63. X;;-----------------------------------------------------------
  64. X
  65. X(defun fe-copy.int (&key (test-time nil))
  66. X  (car (vcopy '(("perc"
  67. X         @
  68. X         @
  69. X         > @) **)
  70. X          :test-time test-time)))
  71. X
  72. X;;-----------------------------------------------------------
  73. X
  74. X(defun fe-xtrct.int ()
  75. X  (vget '(("perc"
  76. X       @
  77. X       @
  78. X       (> @@) **))))
  79. X
  80. X;;-----------------------------------------------------------
  81. X
  82. X(defun fe-get.int ()
  83. X  (car (vput "%" '((~ "perc"
  84. X              @
  85. X              @
  86. X              > @) **))))
  87. X
  88. X;;-----------------------------------------------------------
  89. X
  90. X
  91. X
  92. X
  93. X;;-----------------------------------------------------------
  94. X;; The following functions which manipulate the locl
  95. X;; sub-partition were composed by Andy MacDonald
  96. X;;-----------------------------------------------------------
  97. X
  98. X
  99. X;;===========================================================
  100. X;;                Local
  101. X;;===========================================================
  102. X
  103. X(defun fe-put.int.locl (locl)
  104. X  (vput locl '((~ "perc"
  105. X          @2
  106. X          (> @ @2)) **)))
  107. X
  108. X;;-----------------------------------------------------------
  109. X
  110. X(defun fe-copy.int.locl (&key (test-time nil))
  111. X  (car (vcopy '(("perc"
  112. X         @2
  113. X         (> @ @2)) **)
  114. X          :test-time test-time)))
  115. X
  116. X;;-----------------------------------------------------------
  117. X
  118. X(defun fe-xtrct.int.locl ()
  119. X  (vget '(("perc"
  120. X       @2
  121. X       ((> @@) @2)) **)))
  122. X
  123. X;;-----------------------------------------------------------
  124. X
  125. X(defun fe-get.int.locl ()
  126. X  (car (vput '((~ "perc"
  127. X          @2
  128. X          (> @ @2)) **))))
  129. X
  130. X;;-----------------------------------------------------------
  131. X
  132. X
  133. X
  134. X;;===========================================================
  135. X;;               Local Objects
  136. X;;===========================================================
  137. X
  138. X(defun fe-jam.int.locl.ob (ob)
  139. X  (vput ob '((~ "perc"
  140. X        @2
  141. X        ((^ @@) @2)) **)))
  142. X  
  143. X;;-----------------------------------------------------------
  144. X
  145. X;; objects are (ob-name (attr-list))
  146. X(defun fe-put.int.locl.ob (ob)
  147. X  (cond
  148. X
  149. X   ;; assume object is already there
  150. X   ((car (vput ob `((~ "perc"
  151. X               @2
  152. X               ((> (,(car ob) @) **) @2)) **))))
  153. X
  154. X   ;; object wasn't there, insert new one
  155. X   ((fe-jam.int.locl.ob ob))
  156. X   ))
  157. X
  158. X;;-----------------------------------------------------------
  159. X
  160. X;; pass object name
  161. X(defun fe-copy.int.locl.ob (ob-name &key (test-time nil))
  162. X  (car (vcopy `(("perc"
  163. X         @2
  164. X         ((> (,ob-name @) **) @2)) **)
  165. X          :test-time test-time)))
  166. X
  167. X;;-----------------------------------------------------------
  168. X
  169. X;; pass object name, returns entire object
  170. X(defun fe-xtrct.int.locl.ob (ob-name)
  171. X  (car (vget `(("perc"
  172. X        @2
  173. X        ((> (,ob-name @) **) @2)) **))))
  174. X
  175. X;;-----------------------------------------------------------
  176. X
  177. X(defun fe-get.int.locl.ob (ob-name)
  178. X  (car (vput "%" `((~ "perc"
  179. X              @2
  180. X              (((~ ,ob-name > @) **) @2)) **))))
  181. X
  182. X;;-----------------------------------------------------------
  183. X
  184. X
  185. X
  186. X;;===========================================================
  187. X;;          Local Object - Complex
  188. X;;===========================================================
  189. X
  190. X(defun fe-copy.int.locl.ob.names ()
  191. X  (vcopy `(("perc"
  192. X        @2
  193. X        (((> @ @) **) @2)) **)
  194. X     :freq "all"))
  195. X
  196. X;;-----------------------------------------------------------
  197. X
  198. X
  199. X
  200. X
  201. X;;===========================================================
  202. X;;          Local Object Attributes
  203. X;;===========================================================
  204. X
  205. X(defun fe-jam.int.locl.ob.attr (ob-name attr)
  206. X  (cond
  207. X   ;; assume object exists, add new attr
  208. X   ((vput attr `((~ "perc"
  209. X            @2
  210. X            (((~ ,ob-name (^ @@)) **) @2)) **)))
  211. X
  212. X   ;; object didn't exist, add new object with new attr.
  213. X   ((fe-jam.int.locl.ob `(,ob-name (,attr))))
  214. X   ))
  215. X
  216. X;;-----------------------------------------------------------
  217. X
  218. X(defun fe-put.int.locl.ob.attr (ob-name attr)
  219. X  (cond
  220. X   
  221. X   ;; assume the object and attr exist, swap in new attr
  222. X   ((car (vput attr `((~ "perc"
  223. X             @2
  224. X             (((~ ,ob-name (> (,(car attr) @) **)) **) @2)) **))))
  225. X    
  226. X   ;; attr didn't exist, add new attr
  227. X   ((fe-jam.int.locl.ob.attr ob-name attr))
  228. X   ))
  229. X
  230. X;;-----------------------------------------------------------
  231. X
  232. X(defun fe-xtrct.int.locl.ob.attr (ob-name attr-name)
  233. X  (car (vget `(("perc"
  234. X        @2
  235. X        (((,ob-name (> (,attr-name @) **)) **) @2)) **))))
  236. X
  237. X;;-----------------------------------------------------------
  238. X
  239. X(defun fe-get.int.locl.ob.attr (ob-name attr-name)
  240. X  (car (vput "%" `((~ "perc"
  241. X              @2
  242. X              (((~ ,ob-name ((~ ,attr-name > @) **)) **) @2)) **))))
  243. X
  244. X;;-----------------------------------------------------------
  245. X
  246. X;; returns attr struct
  247. X(defun fe-copy.int.locl.ob.attr (ob-name attr-name &key (test-time nil))
  248. X  (car (vcopy `(("perc"
  249. X         @2
  250. X         (((,ob-name (> (,attr-name @) **)) **) @2)) **)
  251. X          :test-time test-time)))
  252. X  
  253. X;;-----------------------------------------------------------
  254. X
  255. X
  256. X
  257. X;;===========================================================
  258. X;;         Local Object Attributes - Complex
  259. X;;===========================================================
  260. X
  261. X;; returns list of boundary attribute names
  262. X(defun fe-copy.int.locl.ob.attr.names (ob-name)
  263. X  (vcopy `(("perc"
  264. X        @2
  265. X        (((,ob-name ((> @ @) **)) **) @2)) **)
  266. X     :freq "all"))
  267. X
  268. X;;-----------------------------------------------------------
  269. X
  270. X;; returns attr val
  271. X(defun fe-copy.int.locl.ob.attr.val (ob-name attr-name)
  272. X  (car (vcopy `(("perc"
  273. X         @2
  274. X         (((,ob-name ((,attr-name > @) **)) **) @2)) **))))
  275. X  
  276. X;;-----------------------------------------------------------
  277. X
  278. X
  279. X
  280. X;;===========================================================
  281. X;;              Sublings
  282. X;;===========================================================
  283. X
  284. X(defun fe-put.int.subs (subs)
  285. X  (vput subs '((~ "perc"
  286. X          @2
  287. X          (@ > @ @)) **)))
  288. X
  289. X;;-----------------------------------------------------------
  290. X
  291. X;; cache this frequently used pattern in C level fern.
  292. X;; later, calls to fe-copy.int.subs use precomputed pattern.
  293. X
  294. X(fbase-init-copy.int.subs '(("perc"
  295. X                 @2
  296. X                 (@ > @ @)) **))
  297. X
  298. X#|
  299. X(defun fe-copy.int.subs (&key (test-time nil))
  300. X  (car (vcopy '(("perc"
  301. X         @2
  302. X         (@ > @ @)) **)
  303. X          :test-time test-time)))
  304. X|#
  305. X;;-----------------------------------------------------------
  306. X
  307. X(defun fe-xtrct.int.subs ()
  308. X  (vget '(("perc"
  309. X       @2
  310. X       (@ (> @@) @)) **)))
  311. X
  312. X;;-----------------------------------------------------------
  313. X
  314. X(defun fe-get.int.subs ()
  315. X  (car (vput "%" '((~ "perc"
  316. X              @2
  317. X              (@ > @ @)) **))))
  318. X
  319. X;;-----------------------------------------------------------
  320. X
  321. X
  322. X;;===========================================================
  323. X;;              Sublings Entities
  324. X;;===========================================================
  325. X
  326. X(defun fe-jam.int.subs.ent (ent)
  327. X  (vput ent '((~ "perc"
  328. X         @2
  329. X         (@ (^ @@) @)) **)))
  330. X
  331. X;;-----------------------------------------------------------
  332. X
  333. X;; an ent is: (uid (ob-list))
  334. X(defun fe-put.int.subs.ent (ent)
  335. X  (cond
  336. X
  337. X   ;; assume the ent exists, swap in the new ent
  338. X   ((car (vput ent `((~ "perc"
  339. X            @2
  340. X            (@ (> (,(car ent) @) **) @)
  341. X            ) **))))
  342. X
  343. X   ;; ent didn't exist, insert new ent
  344. X   ((fe-jam.int.subs.ent ent))
  345. X   ))
  346. X              
  347. X;;-----------------------------------------------------------
  348. X
  349. X(defun fe-copy.int.subs.ent (uid &key (test-time nil))
  350. X  (car (vcopy `(("perc"
  351. X         @2
  352. X         (@ (> (,uid @) **) @)
  353. X         ) **)
  354. X          :test-time test-time)))
  355. X
  356. X;;-----------------------------------------------------------
  357. X
  358. X(defun fe-xtrct.int.subs.ent (uid)
  359. X  (car (vget `(("perc"
  360. X        @2
  361. X        (@ (> (,uid @) **) @)
  362. X        ) **))))
  363. X
  364. X;;-----------------------------------------------------------
  365. X
  366. X(defun fe-get.int.subs.ent (uid)
  367. X  (car (vput "%" `((~ "perc"
  368. X              @2
  369. X              (@ ((~ ,uid > @) **) @)
  370. X              ) **))))
  371. X
  372. X;;-----------------------------------------------------------
  373. X
  374. X
  375. X
  376. X;;===========================================================
  377. X;;         Sublings Entities - Complex
  378. X;;===========================================================
  379. X
  380. X(defun fe-copy.int.subs.uids ()
  381. X  (vcopy '(("perc"
  382. X        @2
  383. X        (@ ((> @ @) **) @)
  384. X        ) **)
  385. X     :freq "all"))
  386. X
  387. X;;-----------------------------------------------------------
  388. X
  389. X
  390. X
  391. X
  392. X;;===========================================================
  393. X;;          Sublings Entities Objects
  394. X;;===========================================================
  395. X
  396. X
  397. X(defun fe-jam.int.subs.ent.ob (uid ob)
  398. X  (cond
  399. X
  400. X   ;; assume entity exists, insert new object
  401. X   ((vput ob `((~ "perc"
  402. X          @2
  403. X          (@ ((~ ,uid (^ @@)) **) @)
  404. X          ) **)))
  405. X
  406. X   ;; entity wasn't there, insert new entity with new object
  407. X   ((fe-jam.int.subs.ent `(,uid (,ob))))
  408. X   ))
  409. X   
  410. X;;-----------------------------------------------------------
  411. X
  412. X;; ob is a normal object structure: (name (attr-list))
  413. X(defun fe-put.int.subs.ent.ob (uid ob)
  414. X  (cond
  415. X
  416. X   ;; assume entity and object exist, swap in new object
  417. X   ((car (vput ob `((~ "perc"
  418. X               @2               
  419. X               (@ ((~ ,uid (> (,(car ob) @) **)) **) @)
  420. X               ) **))))
  421. X   
  422. X   ;; object wasn't there, assume entity exists, insert new object
  423. X   ((fe-jam.int.subs.ent.ob uid ob))
  424. X   ))
  425. X   
  426. X;;-----------------------------------------------------------
  427. X
  428. X(defun fe-copy.int.subs.ent.ob (uid ob-name &key (test-time nil))
  429. X  (car (vcopy `(("perc"
  430. X         @2
  431. X         (@ ((,uid (> (,ob-name @) **)) **) @)
  432. X         ) **)
  433. X          :test-time test-time)))
  434. X
  435. X;;-----------------------------------------------------------
  436. X
  437. X(defun fe-xtrct.int.subs.ent.ob (uid ob-name)
  438. X  (car (vget `(("perc"
  439. X        @2
  440. X        (@ ((,uid (> (,ob-name @) **)) **) @)
  441. X        ) **))))
  442. X
  443. X;;-----------------------------------------------------------
  444. X
  445. X(defun fe-get.int.subs.ent.ob (uid ob-name)
  446. X  (car (vput "%" `((~ "perc"
  447. X              @2
  448. X              (@ ((~ ,uid ((~ ,ob-name > @) **)) **) @)
  449. X              ) **))))
  450. X
  451. X;;-----------------------------------------------------------
  452. X
  453. X
  454. X
  455. X;;===========================================================
  456. X;;         Subling Entities Objects - Complex
  457. X;;===========================================================
  458. X
  459. X;; pass uid, get list of it's ob names
  460. X(defun fe-copy.int.subs.ent.ob.names (uid)
  461. X  (vcopy `(("perc"
  462. X        @2
  463. X        (@ ((,uid ((> @ @) **)) **) @)
  464. X        ) **)
  465. X     :freq "all"))
  466. X
  467. X;;-----------------------------------------------------------
  468. X
  469. X
  470. X
  471. X
  472. X;;===========================================================
  473. X;;         Subling Entities Objects Attributes
  474. X;;===========================================================
  475. X
  476. X
  477. X(defun fe-jam.int.subs.ent.ob.attr (uid ob-name attr)
  478. X  (cond
  479. X   ;; assume entity and ob exists, insert new attr
  480. X   ((vput attr `((~ "perc"
  481. X            @2
  482. X            (@
  483. X             ((~ ,uid ((~ ,ob-name (^ @@)) **)) **)
  484. X             @)
  485. X            ) **)))
  486. X  
  487. X   ;; ob wasn't there, insert new ob with new attr
  488. X   ((fe-jam.int.subs.ent.ob uid `(,ob-name (,attr))))
  489. X   ))
  490. X
  491. X;;-----------------------------------------------------------
  492. X
  493. X;; attr is ("attr-name" attr-val)
  494. X(defun fe-put.int.subs.ent.ob.attr (uid ob-name attr)
  495. X  (cond
  496. X   ;; assume the ent, ob and attr exist, swap in new attr
  497. X   ((car (vput attr `((~ "perc"
  498. X             @2
  499. X             (@ 
  500. X              ((~ ,uid ((~ ,ob-name (> (,(car attr) @) **)) **)) **)
  501. X              @)
  502. X             ) **))))
  503. X
  504. X   ;; attr wasn't there, insert new attr
  505. X   ((fe-jam.int.subs.ent.ob.attr uid ob-name attr))
  506. X   ))
  507. X   
  508. X;;-----------------------------------------------------------
  509. X
  510. X;; pass uid, ob-num, attr-name
  511. X(defun fe-copy.int.subs.ent.ob.attr (uid ob-num attr-name &key (test-time nil))
  512. X  (car (vcopy `(("perc"
  513. X         @2
  514. X         (@
  515. X          ((,uid ((,ob-num (> (,attr-name @) **)) **)) **)
  516. X          @)
  517. X         ) **)
  518. X          :test-time test-time)))
  519. X
  520. X;;-----------------------------------------------------------
  521. X
  522. X;; pass uid, ob-num, attr-name
  523. X(defun fe-xtrct.int.subs.ent.ob.attr (uid ob-num attr-name)
  524. X  (car (vget `(("perc"
  525. X        @2
  526. X        (@
  527. X         ((,uid ((,ob-num (> (,attr-name @) **)) **)) **)
  528. X         @)
  529. X        ) **))))
  530. X
  531. X;;-----------------------------------------------------------
  532. X
  533. X;; pass uid, ob-num, attr-name
  534. X(defun fe-get.int.subs.ent.ob.attr (uid ob-num attr-name)
  535. X  (car (vput "%" `((~ "perc"
  536. X              @2
  537. X              (@
  538. X               ((~ ,uid ((~ ,ob-num ((~ ,attr-name > @) **)) **)) **)
  539. X               @)
  540. X              ) **))))
  541. X
  542. X;;-----------------------------------------------------------
  543. X
  544. X
  545. X
  546. X;;===========================================================
  547. X;;    Subling Entities Objects Attributes - Complex
  548. X;;===========================================================
  549. X
  550. X;; pass uid and ob, return attr-list
  551. X(defun fe-copy.int.subs.ent.ob.attr.names (uid ob-name)
  552. X  (vcopy `(("perc"
  553. X        @2
  554. X        (@
  555. X         ((,uid ((,ob-name ((> @ @) **)) **)) **)
  556. X         @)
  557. X        ) **)
  558. X     :freq "all"))
  559. X
  560. X;;-----------------------------------------------------------
  561. X
  562. X;; pass attr, return values of all objects of all sibs
  563. X(defun fe-copy.int.subs.attr.vals (attr-name)
  564. X  (vcopy `(("perc"
  565. X        @2
  566. X        (@
  567. X         ((@ ((@ ((,attr-name > @) **)) **)) **)
  568. X         @)
  569. X        ) **)
  570. X     :freq "all"))
  571. X
  572. X;;-----------------------------------------------------------
  573. X
  574. X;; pass uid, ob-num, attr-name
  575. X(defun fe-copy.int.subs.ent.ob.attr.val (uid ob-num attr-name)
  576. X  (car (vcopy `(("perc"
  577. X         @2
  578. X         (@
  579. X          ((,uid ((,ob-num ((,attr-name > @) **)) **)) **)
  580. X          @)
  581. X         ) **))))
  582. X
  583. X;;-----------------------------------------------------------
  584. X
  585. X
  586. X
  587. X
  588. X
  589. X;;===========================================================
  590. X;;               Filters
  591. X;;===========================================================
  592. X
  593. X(defun fe-put.int.fltrs (fltr)
  594. X  (vput fltr '((~ "perc"
  595. X          @2
  596. X          (@2 > @)) **)))
  597. X
  598. X;;-----------------------------------------------------------
  599. X
  600. X(defun fe-copy.int.fltrs (&key (test-time nil))
  601. X  (car (vcopy '(("perc"
  602. X         @2
  603. X         (@2 > @)) **)
  604. X          :test-time test-time)))
  605. X
  606. X;;-----------------------------------------------------------
  607. X
  608. X(defun fe-xtrct.int.fltrs ()
  609. X  (vget '(("perc"
  610. X       @2
  611. X       (@2 (> @@))) **)))
  612. X
  613. X;;-----------------------------------------------------------
  614. X
  615. X(defun fe-get.int.fltrs ()
  616. X  (car (vput "%" '((~ "perc"
  617. X              @2
  618. X              (@2 > @)) **))))
  619. X
  620. X;;-----------------------------------------------------------
  621. X
  622. X
  623. X
  624. X;;===========================================================
  625. X;;               Fltrs Entities
  626. X;;===========================================================
  627. X
  628. X(defun fe-jam.int.fltrs.ent (ent)
  629. X  (vput ent '((~ "perc"
  630. X         @2
  631. X         (@2 (^ @@))) **)))
  632. X
  633. X;;-----------------------------------------------------------
  634. X
  635. X;; an ent is: (uid (ob-list))
  636. X(defun fe-put.int.fltrs.ent (ent)
  637. X  (cond
  638. X
  639. X   ;; assume the ent exists, swap in the new ent
  640. X   ((car (vput ent `((~ "perc"
  641. X            @2
  642. X            (@2 (> (,(car ent) @) **))
  643. X            ) **))))
  644. X
  645. X   ;; ent didn't exist, insert new ent
  646. X   ((fe-jam.int.fltrs.ent ent))
  647. X   ))
  648. X              
  649. X;;-----------------------------------------------------------
  650. X
  651. X(defun fe-copy.int.fltrs.ent (uid &key (test-time nil))
  652. X  (car (vcopy `(("perc"
  653. X         @2
  654. X         (@2 (> (,uid @) **))
  655. X         ) **)
  656. X          :test-time test-time)))
  657. X
  658. X;;-----------------------------------------------------------
  659. X
  660. X(defun fe-xtrct.int.fltrs.ent (uid)
  661. X  (car (vget `(("perc"
  662. X        @2
  663. X        (@2 (> (,uid @) **))
  664. X        ) **))))
  665. X
  666. X;;-----------------------------------------------------------
  667. X
  668. X(defun fe-get.int.fltrs.ent (uid)
  669. X  (car (vput "%" `((~ "perc"
  670. X              @2
  671. X              (@2 ((~ ,uid > @) **))
  672. X              ) **))))
  673. X
  674. X;;-----------------------------------------------------------
  675. X
  676. X
  677. X
  678. X
  679. X;;===========================================================
  680. X;;          Internal Entity Filter Processing
  681. X;;===========================================================
  682. X
  683. X
  684. X;;-----------------------------------------------------------
  685. X
  686. X(defun fe-fltr.int.subs (uid &key (test-time nil))
  687. X  (delete uid
  688. X      (fe-copy.int.subs :test-time test-time)
  689. X      :test (lambda (x y) (equal x (car y)))))
  690. X  
  691. X;;-----------------------------------------------------------
  692. X
  693. X(defun fe-fltr.int.subs.uids (uid)
  694. X  (delete uid 
  695. X      (fe-copy.int.subs.uids)
  696. X      :test 'equal))
  697. X  
  698. X;;-----------------------------------------------------------
  699. X
  700. X
  701. X
  702. X
  703. END_OF_FILE
  704. if test 16110 -ne `wc -c <'kernel_private/src/fern/fe_int.lsp'`; then
  705.     echo shar: \"'kernel_private/src/fern/fe_int.lsp'\" unpacked with wrong size!
  706. fi
  707. # end of 'kernel_private/src/fern/fe_int.lsp'
  708. fi
  709. if test -f 'kernel_private/src/talk/socket.c' -a "${1}" != "-c" ; then 
  710.   echo shar: Will not clobber existing file \"'kernel_private/src/talk/socket.c'\"
  711. else
  712. echo shar: Extracting \"'kernel_private/src/talk/socket.c'\" \(16709 characters\)
  713. sed "s/^X//" >'kernel_private/src/talk/socket.c' <<'END_OF_FILE'
  714. X/****************************************************************************************
  715. X *                                            *
  716. X * file: socket.c                                                *
  717. X *                                            *
  718. X * November 14, 1990: The network and transport layer for inter-entity message passing    *
  719. X *               library, 'talk' for the VEOS project.                             *
  720. X *                                            *
  721. X * by Geoffrey P. Coco at the HITLab, Seattle.                          *
  722. X * these functions are based on BSD socket code by Dan Pezely.                       *
  723. X *                                            *
  724. X ****************************************************************************************/
  725. X
  726. X/****************************************************************************************
  727. X * Copyright (C) 1992  Geoffrey P. Coco, Human Interface Technology Lab, Seattle    *
  728. X ****************************************************************************************/
  729. X
  730. X
  731. X
  732. X/****************************************************************************************
  733. X *                      include the papa include file                */
  734. X
  735. X#include "kernel.h"
  736. X
  737. X#include <sys/types.h>
  738. X#include <sys/socket.h>
  739. X#include <netinet/in.h>
  740. X#include <netinet/tcp.h>
  741. X#include <netdb.h>            /* for get_*_byname() */
  742. X#include <stropts.h>            /* ioctl() streamio */
  743. X#include <fcntl.h>
  744. X#include "signal.h"
  745. X
  746. X/****************************************************************************************/
  747. X
  748. X
  749. X
  750. X/****************************************************************************************
  751. X *                     forward function declarations                */
  752. X
  753. XTVeosErr Sock_Connect();
  754. XTVeosErr Sock_Listen();
  755. XTVeosErr Sock_ReadSelect();
  756. XTVeosErr Sock_WriteSelect();
  757. XTVeosErr Sock_Accept();
  758. XTVeosErr Sock_Transmit();
  759. XTVeosErr Sock_Receive();
  760. XTVeosErr Sock_Close();
  761. X
  762. X/****************************************************************************************/
  763. X
  764. X
  765. X
  766. X/****************************************************************************************
  767. X *                     local function declarations                */
  768. X
  769. XTVeosErr Sock_MixItUp();
  770. XTVeosErr Sock_ResolveHost();
  771. Xu_long Sock_ConvertAddr();
  772. X
  773. X/****************************************************************************************/
  774. X
  775. X
  776. X
  777. X
  778. X/****************************************************************************************/
  779. XTVeosErr Sock_Connect(iSocketFD, pUid, sProtocolName)
  780. X    int         *iSocketFD;
  781. X    TPUid        pUid;
  782. X    char         *sProtocolName;
  783. X{
  784. X    struct sockaddr_in  socketName;
  785. X    TVeosErr        iErr;
  786. X    int            iProto, iOption, iBufSize;
  787. X    
  788. X
  789. X    /** translate given network params into useable form **/
  790. X
  791. X    iErr = Sock_MixItUp(&pUid->iPort, sProtocolName, &iProto);
  792. X    if (iErr == VEOS_SUCCESS) {
  793. X
  794. X
  795. X    /** copy the address of the receiving host **/
  796. X
  797. X    socketName.sin_addr.s_addr = pUid->lHost;
  798. X
  799. X        
  800. X    /** create socket with specified protocol **/
  801. X    
  802. X    socketName.sin_family = AF_INET;
  803. X    socketName.sin_port = htons(pUid->iPort);
  804. X    
  805. X    *iSocketFD = socket(socketName.sin_family, SOCK_STREAM, iProto);
  806. X    
  807. X    if (*iSocketFD == TALK_BOGUS_FD)
  808. X        iErr = TALK_CREATE;
  809. X    
  810. X    else {
  811. X        
  812. X        
  813. X        /** attempt to connect to given address **/
  814. X        
  815. X        if (connect(*iSocketFD, &socketName, sizeof(socketName)) < 0)
  816. X        
  817. X        iErr = TALK_CONNECT;
  818. X        
  819. X        
  820. X        else {
  821. X/*
  822. X        iBufSize = 16384;
  823. X        if (setsockopt(*iSocketFD, SOL_SOCKET, SO_SNDBUF,
  824. X                   (char *) &iBufSize, sizeof(int)) < 0)
  825. X            iErr = TALK_FLAGS;
  826. X*/            
  827. X        iOption = TRUE;
  828. X        if (setsockopt(*iSocketFD, IPPROTO_TCP, TCP_NODELAY,
  829. X                   &iOption, sizeof(int)) == -1)
  830. X            iErr = TALK_FLAGS;
  831. X
  832. X        /** set non-blocking write bit **/
  833. X        
  834. X        fcntl(*iSocketFD, F_SETFL, FNDELAY);
  835. X        
  836. X        FD_SET(*iSocketFD, &OPEN_WRITE_SOCKETS);
  837. X        }
  838. X        
  839. X        if (iErr != VEOS_SUCCESS)
  840. X        Sock_Close(iSocketFD);
  841. X        }
  842. X    }
  843. X
  844. X    return(iErr);
  845. X
  846. X    } /* Sock_Connect */
  847. X/****************************************************************************************/
  848. X
  849. X
  850. X
  851. X
  852. X/****************************************************************************************/
  853. XTVeosErr Sock_Listen(iSocketFD, iPortNumber, sProtocolName, iAttitude)
  854. X    int         *iSocketFD;
  855. X    int         iPortNumber;
  856. X    char         *sProtocolName;
  857. X    int            iAttitude;
  858. X{
  859. X    struct sockaddr_in  socketName;
  860. X    TVeosErr        iErr;
  861. X    int            iProto, iOption;
  862. X    int            iZoot;
  863. X
  864. X    iErr = Sock_MixItUp(&iPortNumber, sProtocolName, &iProto);
  865. X    if (iErr == VEOS_SUCCESS) {
  866. X
  867. X
  868. X
  869. X    /** create socket with specified protocol **/
  870. X
  871. X    socketName.sin_family = AF_INET;   /* specify socket to be of INTERNET family */
  872. X
  873. X    *iSocketFD = socket(socketName.sin_family, SOCK_STREAM, iProto);
  874. X
  875. X    if (*iSocketFD == TALK_BOGUS_FD)
  876. X        iErr = TALK_CREATE;
  877. X
  878. X    else {
  879. X        socketName.sin_addr.s_addr = htonl(INADDR_ANY);
  880. X        socketName.sin_port = htons(iPortNumber);
  881. X        
  882. X        if (iAttitude == TALK_AGRESSIVE) {
  883. X        iOption = TRUE;
  884. X        if (setsockopt(*iSocketFD, SOL_SOCKET, SO_REUSEADDR,
  885. X                   &iOption, sizeof(int)) == -1)
  886. X            iErr = TALK_FLAGS;
  887. X        }
  888. X        
  889. X        if (iErr == VEOS_SUCCESS) {
  890. X        
  891. X        /** register this socket with system for us **/
  892. X        
  893. X        if (bind(*iSocketFD, &socketName, sizeof(socketName)) < 0) {
  894. X            
  895. X            iErr = TALK_BIND;
  896. X            }
  897. X        
  898. X        else {
  899. X            /** listen on the socket **/
  900. X            
  901. X            if (listen(*iSocketFD, TALK_QUEUE_SIZE ) < 0)
  902. X            iErr = TALK_LISTEN;
  903. X            
  904. X            else {
  905. X            /** have this socket generate an interrupt
  906. X             ** when another entity connects.
  907. X             **/
  908. X/*
  909. X            fcntl(*iSocketFD, F_SETOWN, getpid());
  910. X            fcntl(*iSocketFD, F_SETFL, FASYNC);
  911. X*/            
  912. X            FD_SET(*iSocketFD, &OPEN_READ_SOCKETS);
  913. X            }
  914. X            }
  915. X        }        
  916. X        }
  917. X    if (iErr != VEOS_SUCCESS) {
  918. X        
  919. X        Sock_Close(iSocketFD);
  920. X        *iSocketFD = TALK_BOGUS_FD;
  921. X        }
  922. X    }
  923. X
  924. X    return(iErr);
  925. X    
  926. X    } /* Sock_Listen */
  927. X/****************************************************************************************/
  928. X
  929. X
  930. X
  931. X
  932. X/****************************************************************************************/
  933. XTVeosErr Sock_ReadSelect(iSocketFD)
  934. X    int        iSocketFD;
  935. X{
  936. X    struct timeval      timeVal;
  937. X    fd_set          tempFDSet;
  938. X    int         iSize;
  939. X    TVeosErr        iErr;
  940. X    
  941. X    
  942. X    iErr = VEOS_SUCCESS;
  943. X    
  944. X    
  945. X    /** create a local copy of the fd_set since it gets modified by select() **/
  946. X    
  947. X    bcopy((char*) &OPEN_READ_SOCKETS, (char*) &tempFDSet, sizeof(fd_set));
  948. X    
  949. X    
  950. X    
  951. X    /** some implementations of select() might modify timeVal, so we    **
  952. X     ** must keep resetting it rather then making it global or static.    **/
  953. X    
  954. X    timeVal.tv_sec = 0;
  955. X    timeVal.tv_usec = 0;
  956. X    
  957. X    iSize = select(FD_SETSIZE, &tempFDSet, nil, nil, &timeVal);
  958. X    
  959. X    if (iSize <  0)
  960. X    iErr = TALK_SELECT;
  961. X    
  962. X    else if (iSize == 0)
  963. X    iErr = TALK_SELECT_TIMEOUT;
  964. X    
  965. X    else if (!FD_ISSET(iSocketFD, &tempFDSet))
  966. X    iErr = TALK_NOCONN;
  967. X    
  968. X    
  969. X    return(iErr);
  970. X    
  971. X    } /* Sock_ReadSelect */
  972. X/****************************************************************************************/
  973. X
  974. X
  975. X
  976. X
  977. X/****************************************************************************************
  978. X * Sock_ReadSelect                                    */
  979. X
  980. XTVeosErr Sock_WriteSelect(iSocketFD)
  981. X     int        iSocketFD;
  982. X{
  983. X    struct timeval      timeVal;
  984. X    fd_set          tempFDSet;
  985. X    int         iSize;
  986. X    TVeosErr        iErr;
  987. X    
  988. X    
  989. X    iErr = VEOS_SUCCESS;
  990. X    
  991. X    
  992. X    /** create a local copy of the fd_set since it gets modified by select() **/
  993. X    
  994. X    bcopy((char*) &OPEN_WRITE_SOCKETS, (char*) &tempFDSet, sizeof(fd_set));
  995. X    
  996. X    
  997. X    
  998. X    /** some implementations of select() might modify timeVal, so we    **
  999. X     ** must keep resetting it rather then making it global or static.    **/
  1000. X    
  1001. X    timeVal.tv_sec = 0;
  1002. X    timeVal.tv_usec = 0;
  1003. X    
  1004. X    iSize = select(FD_SETSIZE, nil, &tempFDSet, nil, &timeVal);
  1005. X    
  1006. X    if (TRAP_FLAGS & 0x00000001 << SIGPIPE) {
  1007. X    TRAP_FLAGS = TRAP_FLAGS & ~(0x00000001 << SIGPIPE);
  1008. X    TERMINATE = FALSE;
  1009. X    iErr = TALK_CONN_CLOSED;
  1010. X    }
  1011. X
  1012. X    else if (iSize <  0)
  1013. X    iErr = TALK_SELECT;
  1014. X    
  1015. X    else if (iSize == 0)
  1016. X    iErr = TALK_SELECT_TIMEOUT;
  1017. X    
  1018. X    else if (!FD_ISSET(iSocketFD, &tempFDSet))
  1019. X    iErr = TALK_NOCONN;
  1020. X    
  1021. X    
  1022. X    return(iErr);
  1023. X    
  1024. X    } /* Sock_WriteSelect */
  1025. X/****************************************************************************************/
  1026. X
  1027. X
  1028. X
  1029. X
  1030. X/****************************************************************************************
  1031. X * Sock_Accept                                        */
  1032. X
  1033. XTVeosErr Sock_Accept(iSocketFD, iSocketIOFD)
  1034. X    int         iSocketFD;
  1035. X    int         *iSocketIOFD;
  1036. X{
  1037. X    TVeosErr        iErr;
  1038. X    int            iBufSize;
  1039. X
  1040. X    iErr = TALK_ACCEPT;
  1041. X    
  1042. X    *iSocketIOFD = accept(iSocketFD, nil, nil);
  1043. X    if (*iSocketIOFD >= 0) {
  1044. X
  1045. X        /** setup socket for large buffers and non-blocking reading **/
  1046. X/*
  1047. X    iBufSize = 16384;
  1048. X    if (setsockopt(*iSocketIOFD, SOL_SOCKET, SO_RCVBUF,
  1049. X               (char *) &iBufSize, sizeof(int)) < 0 ||
  1050. X*/
  1051. X    /** convert msgsock to streams message-nondiscard-mode **/
  1052. X
  1053. X    if (fcntl(*iSocketIOFD, F_SETFL, FNDELAY) == -1)
  1054. X        Sock_Close(iSocketIOFD);
  1055. X
  1056. X    else {
  1057. X        FD_SET(*iSocketIOFD, &OPEN_READ_SOCKETS);
  1058. X        iErr = VEOS_SUCCESS;
  1059. X        }
  1060. X    }
  1061. X
  1062. X    return(iErr);
  1063. X    
  1064. X} /* Sock_Accept */
  1065. X/****************************************************************************************/
  1066. X
  1067. X
  1068. X
  1069. X
  1070. X/****************************************************************************************
  1071. X * Sock_Transmit                                        */
  1072. X
  1073. XTVeosErr Sock_Transmit(iSocketFD, sMessage, pLen)
  1074. X    int            iSocketFD;
  1075. X    char        *sMessage;
  1076. X    int            *pLen;
  1077. X{    
  1078. X    int            iNetAction;
  1079. X    TVeosErr        iErr;
  1080. X    boolean        bTrap;
  1081. X
  1082. X    iErr = VEOS_FAILURE;    
  1083. X    
  1084. X
  1085. X    /** send the string to the given socket destination **/
  1086. X    
  1087. X    iNetAction = write(iSocketFD, sMessage, *pLen);
  1088. X
  1089. X    CATCH_TRAP(SIGPIPE, bTrap);
  1090. X    if (bTrap)
  1091. X    iErr = TALK_CONN_CLOSED;
  1092. X
  1093. X
  1094. X    else if (iNetAction < 0) {
  1095. X
  1096. X    /** expected result when can't write **/
  1097. X
  1098. X    if (errno == EAGAIN || errno == EWOULDBLOCK)        
  1099. X        iErr = TALK_SPEAK_BLOCKED;
  1100. X
  1101. X    else
  1102. X        perror("shell: write");
  1103. X        }
  1104. X
  1105. X    else if (iNetAction > 0) {
  1106. X
  1107. X    *pLen = iNetAction;
  1108. X    iErr = VEOS_SUCCESS;
  1109. X    }
  1110. X
  1111. X    return(iErr);
  1112. X
  1113. X    } /* Sock_Transmit */
  1114. X/****************************************************************************************/
  1115. X
  1116. X
  1117. X
  1118. X
  1119. X/****************************************************************************************
  1120. X * Sock_Receive                                            */
  1121. X
  1122. XTVeosErr Sock_Receive(iSocketFD, sBuffer, iBufferSize)
  1123. X    int            iSocketFD;
  1124. X    char        *sBuffer;
  1125. X    int            *iBufferSize;
  1126. X{
  1127. X    TVeosErr            iErr;
  1128. X    int            iNetAction;
  1129. X
  1130. X
  1131. X    iErr = VEOS_FAILURE;                /* pessimism */
  1132. X
  1133. X
  1134. X    /** look for unread data in socket **/
  1135. X
  1136. X    iNetAction = read(iSocketFD, sBuffer, *iBufferSize);
  1137. X
  1138. X
  1139. X
  1140. X    /** connection still open, but no data **/
  1141. X
  1142. X    if (iNetAction < 0) {
  1143. X
  1144. X    /** expected result when no data **/
  1145. X
  1146. X    if (errno == EAGAIN || errno == EWOULDBLOCK)        
  1147. X        iErr = TALK_LISTEN_BLOCKED;
  1148. X
  1149. X    else
  1150. X        perror("shell: read");
  1151. X        }
  1152. X
  1153. X
  1154. X    /** there was some data in the socket **/
  1155. X
  1156. X    else if (iNetAction > 0) {
  1157. X
  1158. X    iErr = VEOS_SUCCESS;
  1159. X    *iBufferSize = iNetAction;
  1160. X    }
  1161. X
  1162. X
  1163. X    /** conneciton closed from other end **/
  1164. X
  1165. X    else
  1166. X        iErr = TALK_CONN_CLOSED;
  1167. X
  1168. X
  1169. X    return(iErr);
  1170. X
  1171. X    } /* Sock_Receive */
  1172. X/****************************************************************************************/
  1173. X
  1174. X
  1175. X
  1176. X
  1177. X/****************************************************************************************
  1178. X ** Inet Socket Close
  1179. X **
  1180. X ** usage:  status = Sock_Close( &socketFD );
  1181. X ** params: pointer to file descriptor of socket
  1182. X ** returns: VEOS_SUCCESS or TALK_CLOSE
  1183. X **/
  1184. X
  1185. XTVeosErr Sock_Close(iSocketFD)
  1186. X    int           *iSocketFD;
  1187. X{
  1188. X    TVeosErr    iErr;
  1189. X    
  1190. X    iErr = VEOS_SUCCESS;    
  1191. X
  1192. X
  1193. X    if (*iSocketFD != TALK_BOGUS_FD) {
  1194. X    
  1195. X    FD_CLR(*iSocketFD, &OPEN_WRITE_SOCKETS);
  1196. X    FD_CLR(*iSocketFD, &OPEN_READ_SOCKETS);
  1197. X
  1198. X    shutdown(*iSocketFD, 2);
  1199. X
  1200. X    if (close(*iSocketFD) == -1)
  1201. X        iErr = TALK_CLOSE;
  1202. X
  1203. X    else
  1204. X        *iSocketFD = TALK_BOGUS_FD;
  1205. X    }
  1206. X
  1207. X    return(iErr);
  1208. X
  1209. X} /* Sock_Close */
  1210. X/****************************************************************************************/
  1211. X
  1212. X
  1213. X
  1214. X
  1215. X/****************************************************************************************
  1216. X *                           local routines                    *
  1217. X ****************************************************************************************/
  1218. X
  1219. X
  1220. X
  1221. X/****************************************************************************************
  1222. X * Sock_MixItUp                                        */
  1223. X
  1224. XTVeosErr Sock_MixItUp(iPortNumber, sProtocolName, iProto)
  1225. X    char        *sProtocolName;
  1226. X    int            *iPortNumber, *iProto;
  1227. X{
  1228. X    struct protoent     *protocolInfo, *getprotobyname();
  1229. X    TVeosErr        iErr;
  1230. X
  1231. X    iErr = VEOS_FAILURE;
  1232. X
  1233. X    if (*iPortNumber > 0) {
  1234. X
  1235. X    protocolInfo = getprotobyname(sProtocolName);
  1236. X    if (protocolInfo == nil)
  1237. X        iErr = TALK_PROTOCOL;
  1238. X
  1239. X    else {
  1240. X        *iProto = protocolInfo->p_proto;
  1241. X        iErr = VEOS_SUCCESS;
  1242. X        }
  1243. X    }
  1244. X
  1245. X    return(iErr);
  1246. X
  1247. X    } /* Sock_MixItUp */
  1248. X/****************************************************************************************/
  1249. X
  1250. X
  1251. X
  1252. X
  1253. X/****************************************************************************************/
  1254. XTVeosErr Sock_ResolveHost(sHostName, pIpAddr)
  1255. X    char        *sHostName;
  1256. X    u_long        *pIpAddr;
  1257. X{
  1258. X    TVeosErr        iErr;
  1259. X
  1260. X
  1261. X    /** host address may already be in internet form **/
  1262. X
  1263. X    if (isdigit(sHostName[0]))
  1264. X    iErr = Sock_StrAddr2IP(sHostName, pIpAddr);
  1265. X
  1266. X    else
  1267. X    iErr = Sock_StrHost2IP(sHostName, pIpAddr);
  1268. X
  1269. X
  1270. X    return(iErr);
  1271. X
  1272. X} /* Sock_ResolveHost */
  1273. X/****************************************************************************************/
  1274. X
  1275. X
  1276. X
  1277. X/****************************************************************************************/
  1278. XTVeosErr Sock_StrHost2IP(sHostName, pIpAddr)
  1279. X    char     *sHostName;
  1280. X    u_long    *pIpAddr;
  1281. X{
  1282. X    TVeosErr        iErr;
  1283. X    struct hostent      *hostInfo, *gethostbyname();
  1284. X    TPHostNode        pFinger;
  1285. X
  1286. X    iErr = VEOS_FAILURE;
  1287. X
  1288. X    if (sHostName) {
  1289. X
  1290. X    /** try to find this host in hash table first **/
  1291. X
  1292. X    for (pFinger = SOCK_HOSTS[sHostName[0] - 'a'];
  1293. X         pFinger;
  1294. X         pFinger = pFinger->pNext) {
  1295. X
  1296. X        if (strcmp(pFinger->sHostName, sHostName) == 0) {
  1297. X        iErr = VEOS_SUCCESS;
  1298. X        break;
  1299. X        }
  1300. X        }
  1301. X
  1302. X
  1303. X    if (!pFinger) {
  1304. X
  1305. X        /** find host by calling unix kernel **/
  1306. X
  1307. X        iErr = TALK_HOST;            
  1308. X        if (hostInfo = gethostbyname(sHostName)) {
  1309. X
  1310. X        iErr = Shell_NewBlock(sizeof(THostNode), &pFinger, "host-node");
  1311. X        if (iErr == VEOS_SUCCESS) {
  1312. X            
  1313. X            pFinger->sHostName = strdup(sHostName);
  1314. X            pFinger->lHost = *(u_long *) hostInfo->h_addr_list[0];
  1315. X            
  1316. X            
  1317. X            /** insert new host into hash table **/
  1318. X            
  1319. X            pFinger->pNext = SOCK_HOSTS[sHostName[0] - 'a'];
  1320. X            SOCK_HOSTS[sHostName[0] - 'a'] = pFinger;
  1321. X            }
  1322. X        }
  1323. X        }
  1324. X
  1325. X    if (pFinger)
  1326. X        *pIpAddr = pFinger->lHost;
  1327. X    }
  1328. X
  1329. X    return(iErr);
  1330. X
  1331. X    } /* Sock_StrHost2IP */
  1332. X/****************************************************************************************/
  1333. X
  1334. X
  1335. X
  1336. X
  1337. X/****************************************************************************************/
  1338. XTVeosErr Sock_IP2StrHost(lIPAddr, sHostName)
  1339. X    u_long    lIPAddr;
  1340. X    char     *sHostName;
  1341. X{
  1342. X    TVeosErr        iErr;
  1343. X    struct hostent      *hostInfo, *gethostbyaddr();
  1344. X    char        *pFinger;
  1345. X
  1346. X    iErr = VEOS_FAILURE;
  1347. X
  1348. X    if (sHostName) {
  1349. X
  1350. X    if (hostInfo = gethostbyaddr((char *) &lIPAddr, sizeof(u_long), AF_INET)) {
  1351. X        strcpy(sHostName, hostInfo->h_name);
  1352. X
  1353. X        if (pFinger = strchr(sHostName, '.'))
  1354. X        pFinger[0] = '\0';
  1355. X
  1356. X        iErr = VEOS_SUCCESS;
  1357. X        }
  1358. X    else
  1359. X        iErr = TALK_HOST;            
  1360. X    }
  1361. X
  1362. X    return(iErr);
  1363. X
  1364. X    } /* Sock_IP2StrHost */
  1365. X/****************************************************************************************/
  1366. X
  1367. X
  1368. X
  1369. X
  1370. X/****************************************************************************************/
  1371. XTVeosErr Sock_StrAddr2IP(sHostName, pIpAddr)
  1372. X    char     *sHostName;
  1373. X    u_long    *pIpAddr;
  1374. X{
  1375. X    u_long    lResult, lTemp;
  1376. X    char     *pCharFinger;
  1377. X    TVeosErr    iErr;
  1378. X
  1379. X    iErr = VEOS_FAILURE;
  1380. X    if (sHostName) {
  1381. X    
  1382. X    lResult = 0;
  1383. X    pCharFinger = sHostName;  
  1384. X    
  1385. X    
  1386. X    /* first byte */
  1387. X    lTemp = (u_long) atoi(pCharFinger);
  1388. X    lResult |= lTemp << 24;
  1389. X    
  1390. X    
  1391. X    /* second byte */
  1392. X    pCharFinger = strchr(pCharFinger, '.');
  1393. X    pCharFinger ++;
  1394. X    
  1395. X    lTemp = (u_long) atoi(pCharFinger);
  1396. X    lResult |= lTemp << 16;
  1397. X    
  1398. X    
  1399. X    /* third byte */
  1400. X    pCharFinger = strchr(pCharFinger, '.');
  1401. X    pCharFinger ++;
  1402. X    
  1403. X    lTemp = (u_long) atoi(pCharFinger);
  1404. X    lResult |= lTemp << 8;
  1405. X    
  1406. X    
  1407. X    /* fourth byte */
  1408. X    pCharFinger = strchr(pCharFinger, '.');
  1409. X    pCharFinger ++;
  1410. X    
  1411. X    lTemp = (u_long) atoi(pCharFinger);
  1412. X    lResult |= lTemp;
  1413. X    
  1414. X    
  1415. X    *pIpAddr = lResult;
  1416. X
  1417. X    iErr = VEOS_SUCCESS;
  1418. X    }
  1419. X
  1420. X    return(iErr);
  1421. X
  1422. X    } /* Sock_StrAddr2IP */
  1423. X/****************************************************************************************/
  1424. X
  1425. X
  1426. X
  1427. X/****************************************************************************************/
  1428. XTVeosErr Sock_IP2StrAddr(lIpAddr, sHostName)
  1429. X    u_long    lIpAddr;
  1430. X    char     *sHostName;
  1431. X{
  1432. X    TVeosErr        iErr;
  1433. X
  1434. X    iErr = VEOS_FAILURE;
  1435. X    if (sHostName) {
  1436. X    
  1437. X    sprintf(sHostName, "%d.%d.%d.%d",
  1438. X        (lIpAddr >> 24) & 0x000000FF,
  1439. X        (lIpAddr >> 16) & 0x000000FF,
  1440. X        (lIpAddr >> 8) & 0x000000FF,
  1441. X        lIpAddr & 0x000000FF);
  1442. X
  1443. X    iErr = VEOS_SUCCESS;
  1444. X    }
  1445. X
  1446. X    return(iErr);
  1447. X
  1448. X    } /* Sock_IP2StrAddr */
  1449. X/****************************************************************************************/
  1450. X
  1451. X
  1452. X
  1453. X
  1454. X
  1455. X
  1456. END_OF_FILE
  1457. if test 16709 -ne `wc -c <'kernel_private/src/talk/socket.c'`; then
  1458.     echo shar: \"'kernel_private/src/talk/socket.c'\" unpacked with wrong size!
  1459. fi
  1460. # end of 'kernel_private/src/talk/socket.c'
  1461. fi
  1462. if test -f 'src/kernel_current/fern/fe_int.lsp' -a "${1}" != "-c" ; then 
  1463.   echo shar: Will not clobber existing file \"'src/kernel_current/fern/fe_int.lsp'\"
  1464. else
  1465. echo shar: Extracting \"'src/kernel_current/fern/fe_int.lsp'\" \(16110 characters\)
  1466. sed "s/^X//" >'src/kernel_current/fern/fe_int.lsp' <<'END_OF_FILE'
  1467. X;;-----------------------------------------------------------
  1468. X;; file: fe_int.lsp
  1469. X;;
  1470. X;; FERN is the Fractal Entity Relativity Node.
  1471. X;; Part of the FE component of the Fern System.
  1472. X;;
  1473. X;; creation: March 28, 1992
  1474. X;;
  1475. X;; by Geoffrey P. Coco at the HITLab, Seattle
  1476. X;;-----------------------------------------------------------
  1477. X
  1478. X
  1479. X;;-----------------------------------------------------------
  1480. X;; Copyright (C) 1992  Geoffrey P. Coco,
  1481. X;; Human Interface Technology Lab, Seattle
  1482. X;;-----------------------------------------------------------
  1483. X
  1484. X
  1485. X;;===========================================================
  1486. X;;              Internal
  1487. X;;===========================================================
  1488. X
  1489. X(defun fe-put.int (int)
  1490. X  (vput int '((~ "perc"
  1491. X         @
  1492. X         @
  1493. X         > @) **)))
  1494. X
  1495. X;;-----------------------------------------------------------
  1496. X
  1497. X(defun fe-copy.int (&key (test-time nil))
  1498. X  (car (vcopy '(("perc"
  1499. X         @
  1500. X         @
  1501. X         > @) **)
  1502. X          :test-time test-time)))
  1503. X
  1504. X;;-----------------------------------------------------------
  1505. X
  1506. X(defun fe-xtrct.int ()
  1507. X  (vget '(("perc"
  1508. X       @
  1509. X       @
  1510. X       (> @@) **))))
  1511. X
  1512. X;;-----------------------------------------------------------
  1513. X
  1514. X(defun fe-get.int ()
  1515. X  (car (vput "%" '((~ "perc"
  1516. X              @
  1517. X              @
  1518. X              > @) **))))
  1519. X
  1520. X;;-----------------------------------------------------------
  1521. X
  1522. X
  1523. X
  1524. X
  1525. X;;-----------------------------------------------------------
  1526. X;; The following functions which manipulate the locl
  1527. X;; sub-partition were composed by Andy MacDonald
  1528. X;;-----------------------------------------------------------
  1529. X
  1530. X
  1531. X;;===========================================================
  1532. X;;                Local
  1533. X;;===========================================================
  1534. X
  1535. X(defun fe-put.int.locl (locl)
  1536. X  (vput locl '((~ "perc"
  1537. X          @2
  1538. X          (> @ @2)) **)))
  1539. X
  1540. X;;-----------------------------------------------------------
  1541. X
  1542. X(defun fe-copy.int.locl (&key (test-time nil))
  1543. X  (car (vcopy '(("perc"
  1544. X         @2
  1545. X         (> @ @2)) **)
  1546. X          :test-time test-time)))
  1547. X
  1548. X;;-----------------------------------------------------------
  1549. X
  1550. X(defun fe-xtrct.int.locl ()
  1551. X  (vget '(("perc"
  1552. X       @2
  1553. X       ((> @@) @2)) **)))
  1554. X
  1555. X;;-----------------------------------------------------------
  1556. X
  1557. X(defun fe-get.int.locl ()
  1558. X  (car (vput '((~ "perc"
  1559. X          @2
  1560. X          (> @ @2)) **))))
  1561. X
  1562. X;;-----------------------------------------------------------
  1563. X
  1564. X
  1565. X
  1566. X;;===========================================================
  1567. X;;               Local Objects
  1568. X;;===========================================================
  1569. X
  1570. X(defun fe-jam.int.locl.ob (ob)
  1571. X  (vput ob '((~ "perc"
  1572. X        @2
  1573. X        ((^ @@) @2)) **)))
  1574. X  
  1575. X;;-----------------------------------------------------------
  1576. X
  1577. X;; objects are (ob-name (attr-list))
  1578. X(defun fe-put.int.locl.ob (ob)
  1579. X  (cond
  1580. X
  1581. X   ;; assume object is already there
  1582. X   ((car (vput ob `((~ "perc"
  1583. X               @2
  1584. X               ((> (,(car ob) @) **) @2)) **))))
  1585. X
  1586. X   ;; object wasn't there, insert new one
  1587. X   ((fe-jam.int.locl.ob ob))
  1588. X   ))
  1589. X
  1590. X;;-----------------------------------------------------------
  1591. X
  1592. X;; pass object name
  1593. X(defun fe-copy.int.locl.ob (ob-name &key (test-time nil))
  1594. X  (car (vcopy `(("perc"
  1595. X         @2
  1596. X         ((> (,ob-name @) **) @2)) **)
  1597. X          :test-time test-time)))
  1598. X
  1599. X;;-----------------------------------------------------------
  1600. X
  1601. X;; pass object name, returns entire object
  1602. X(defun fe-xtrct.int.locl.ob (ob-name)
  1603. X  (car (vget `(("perc"
  1604. X        @2
  1605. X        ((> (,ob-name @) **) @2)) **))))
  1606. X
  1607. X;;-----------------------------------------------------------
  1608. X
  1609. X(defun fe-get.int.locl.ob (ob-name)
  1610. X  (car (vput "%" `((~ "perc"
  1611. X              @2
  1612. X              (((~ ,ob-name > @) **) @2)) **))))
  1613. X
  1614. X;;-----------------------------------------------------------
  1615. X
  1616. X
  1617. X
  1618. X;;===========================================================
  1619. X;;          Local Object - Complex
  1620. X;;===========================================================
  1621. X
  1622. X(defun fe-copy.int.locl.ob.names ()
  1623. X  (vcopy `(("perc"
  1624. X        @2
  1625. X        (((> @ @) **) @2)) **)
  1626. X     :freq "all"))
  1627. X
  1628. X;;-----------------------------------------------------------
  1629. X
  1630. X
  1631. X
  1632. X
  1633. X;;===========================================================
  1634. X;;          Local Object Attributes
  1635. X;;===========================================================
  1636. X
  1637. X(defun fe-jam.int.locl.ob.attr (ob-name attr)
  1638. X  (cond
  1639. X   ;; assume object exists, add new attr
  1640. X   ((vput attr `((~ "perc"
  1641. X            @2
  1642. X            (((~ ,ob-name (^ @@)) **) @2)) **)))
  1643. X
  1644. X   ;; object didn't exist, add new object with new attr.
  1645. X   ((fe-jam.int.locl.ob `(,ob-name (,attr))))
  1646. X   ))
  1647. X
  1648. X;;-----------------------------------------------------------
  1649. X
  1650. X(defun fe-put.int.locl.ob.attr (ob-name attr)
  1651. X  (cond
  1652. X   
  1653. X   ;; assume the object and attr exist, swap in new attr
  1654. X   ((car (vput attr `((~ "perc"
  1655. X             @2
  1656. X             (((~ ,ob-name (> (,(car attr) @) **)) **) @2)) **))))
  1657. X    
  1658. X   ;; attr didn't exist, add new attr
  1659. X   ((fe-jam.int.locl.ob.attr ob-name attr))
  1660. X   ))
  1661. X
  1662. X;;-----------------------------------------------------------
  1663. X
  1664. X(defun fe-xtrct.int.locl.ob.attr (ob-name attr-name)
  1665. X  (car (vget `(("perc"
  1666. X        @2
  1667. X        (((,ob-name (> (,attr-name @) **)) **) @2)) **))))
  1668. X
  1669. X;;-----------------------------------------------------------
  1670. X
  1671. X(defun fe-get.int.locl.ob.attr (ob-name attr-name)
  1672. X  (car (vput "%" `((~ "perc"
  1673. X              @2
  1674. X              (((~ ,ob-name ((~ ,attr-name > @) **)) **) @2)) **))))
  1675. X
  1676. X;;-----------------------------------------------------------
  1677. X
  1678. X;; returns attr struct
  1679. X(defun fe-copy.int.locl.ob.attr (ob-name attr-name &key (test-time nil))
  1680. X  (car (vcopy `(("perc"
  1681. X         @2
  1682. X         (((,ob-name (> (,attr-name @) **)) **) @2)) **)
  1683. X          :test-time test-time)))
  1684. X  
  1685. X;;-----------------------------------------------------------
  1686. X
  1687. X
  1688. X
  1689. X;;===========================================================
  1690. X;;         Local Object Attributes - Complex
  1691. X;;===========================================================
  1692. X
  1693. X;; returns list of boundary attribute names
  1694. X(defun fe-copy.int.locl.ob.attr.names (ob-name)
  1695. X  (vcopy `(("perc"
  1696. X        @2
  1697. X        (((,ob-name ((> @ @) **)) **) @2)) **)
  1698. X     :freq "all"))
  1699. X
  1700. X;;-----------------------------------------------------------
  1701. X
  1702. X;; returns attr val
  1703. X(defun fe-copy.int.locl.ob.attr.val (ob-name attr-name)
  1704. X  (car (vcopy `(("perc"
  1705. X         @2
  1706. X         (((,ob-name ((,attr-name > @) **)) **) @2)) **))))
  1707. X  
  1708. X;;-----------------------------------------------------------
  1709. X
  1710. X
  1711. X
  1712. X;;===========================================================
  1713. X;;              Sublings
  1714. X;;===========================================================
  1715. X
  1716. X(defun fe-put.int.subs (subs)
  1717. X  (vput subs '((~ "perc"
  1718. X          @2
  1719. X          (@ > @ @)) **)))
  1720. X
  1721. X;;-----------------------------------------------------------
  1722. X
  1723. X;; cache this frequently used pattern in C level fern.
  1724. X;; later, calls to fe-copy.int.subs use precomputed pattern.
  1725. X
  1726. X(fbase-init-copy.int.subs '(("perc"
  1727. X                 @2
  1728. X                 (@ > @ @)) **))
  1729. X
  1730. X#|
  1731. X(defun fe-copy.int.subs (&key (test-time nil))
  1732. X  (car (vcopy '(("perc"
  1733. X         @2
  1734. X         (@ > @ @)) **)
  1735. X          :test-time test-time)))
  1736. X|#
  1737. X;;-----------------------------------------------------------
  1738. X
  1739. X(defun fe-xtrct.int.subs ()
  1740. X  (vget '(("perc"
  1741. X       @2
  1742. X       (@ (> @@) @)) **)))
  1743. X
  1744. X;;-----------------------------------------------------------
  1745. X
  1746. X(defun fe-get.int.subs ()
  1747. X  (car (vput "%" '((~ "perc"
  1748. X              @2
  1749. X              (@ > @ @)) **))))
  1750. X
  1751. X;;-----------------------------------------------------------
  1752. X
  1753. X
  1754. X;;===========================================================
  1755. X;;              Sublings Entities
  1756. X;;===========================================================
  1757. X
  1758. X(defun fe-jam.int.subs.ent (ent)
  1759. X  (vput ent '((~ "perc"
  1760. X         @2
  1761. X         (@ (^ @@) @)) **)))
  1762. X
  1763. X;;-----------------------------------------------------------
  1764. X
  1765. X;; an ent is: (uid (ob-list))
  1766. X(defun fe-put.int.subs.ent (ent)
  1767. X  (cond
  1768. X
  1769. X   ;; assume the ent exists, swap in the new ent
  1770. X   ((car (vput ent `((~ "perc"
  1771. X            @2
  1772. X            (@ (> (,(car ent) @) **) @)
  1773. X            ) **))))
  1774. X
  1775. X   ;; ent didn't exist, insert new ent
  1776. X   ((fe-jam.int.subs.ent ent))
  1777. X   ))
  1778. X              
  1779. X;;-----------------------------------------------------------
  1780. X
  1781. X(defun fe-copy.int.subs.ent (uid &key (test-time nil))
  1782. X  (car (vcopy `(("perc"
  1783. X         @2
  1784. X         (@ (> (,uid @) **) @)
  1785. X         ) **)
  1786. X          :test-time test-time)))
  1787. X
  1788. X;;-----------------------------------------------------------
  1789. X
  1790. X(defun fe-xtrct.int.subs.ent (uid)
  1791. X  (car (vget `(("perc"
  1792. X        @2
  1793. X        (@ (> (,uid @) **) @)
  1794. X        ) **))))
  1795. X
  1796. X;;-----------------------------------------------------------
  1797. X
  1798. X(defun fe-get.int.subs.ent (uid)
  1799. X  (car (vput "%" `((~ "perc"
  1800. X              @2
  1801. X              (@ ((~ ,uid > @) **) @)
  1802. X              ) **))))
  1803. X
  1804. X;;-----------------------------------------------------------
  1805. X
  1806. X
  1807. X
  1808. X;;===========================================================
  1809. X;;         Sublings Entities - Complex
  1810. X;;===========================================================
  1811. X
  1812. X(defun fe-copy.int.subs.uids ()
  1813. X  (vcopy '(("perc"
  1814. X        @2
  1815. X        (@ ((> @ @) **) @)
  1816. X        ) **)
  1817. X     :freq "all"))
  1818. X
  1819. X;;-----------------------------------------------------------
  1820. X
  1821. X
  1822. X
  1823. X
  1824. X;;===========================================================
  1825. X;;          Sublings Entities Objects
  1826. X;;===========================================================
  1827. X
  1828. X
  1829. X(defun fe-jam.int.subs.ent.ob (uid ob)
  1830. X  (cond
  1831. X
  1832. X   ;; assume entity exists, insert new object
  1833. X   ((vput ob `((~ "perc"
  1834. X          @2
  1835. X          (@ ((~ ,uid (^ @@)) **) @)
  1836. X          ) **)))
  1837. X
  1838. X   ;; entity wasn't there, insert new entity with new object
  1839. X   ((fe-jam.int.subs.ent `(,uid (,ob))))
  1840. X   ))
  1841. X   
  1842. X;;-----------------------------------------------------------
  1843. X
  1844. X;; ob is a normal object structure: (name (attr-list))
  1845. X(defun fe-put.int.subs.ent.ob (uid ob)
  1846. X  (cond
  1847. X
  1848. X   ;; assume entity and object exist, swap in new object
  1849. X   ((car (vput ob `((~ "perc"
  1850. X               @2               
  1851. X               (@ ((~ ,uid (> (,(car ob) @) **)) **) @)
  1852. X               ) **))))
  1853. X   
  1854. X   ;; object wasn't there, assume entity exists, insert new object
  1855. X   ((fe-jam.int.subs.ent.ob uid ob))
  1856. X   ))
  1857. X   
  1858. X;;-----------------------------------------------------------
  1859. X
  1860. X(defun fe-copy.int.subs.ent.ob (uid ob-name &key (test-time nil))
  1861. X  (car (vcopy `(("perc"
  1862. X         @2
  1863. X         (@ ((,uid (> (,ob-name @) **)) **) @)
  1864. X         ) **)
  1865. X          :test-time test-time)))
  1866. X
  1867. X;;-----------------------------------------------------------
  1868. X
  1869. X(defun fe-xtrct.int.subs.ent.ob (uid ob-name)
  1870. X  (car (vget `(("perc"
  1871. X        @2
  1872. X        (@ ((,uid (> (,ob-name @) **)) **) @)
  1873. X        ) **))))
  1874. X
  1875. X;;-----------------------------------------------------------
  1876. X
  1877. X(defun fe-get.int.subs.ent.ob (uid ob-name)
  1878. X  (car (vput "%" `((~ "perc"
  1879. X              @2
  1880. X              (@ ((~ ,uid ((~ ,ob-name > @) **)) **) @)
  1881. X              ) **))))
  1882. X
  1883. X;;-----------------------------------------------------------
  1884. X
  1885. X
  1886. X
  1887. X;;===========================================================
  1888. X;;         Subling Entities Objects - Complex
  1889. X;;===========================================================
  1890. X
  1891. X;; pass uid, get list of it's ob names
  1892. X(defun fe-copy.int.subs.ent.ob.names (uid)
  1893. X  (vcopy `(("perc"
  1894. X        @2
  1895. X        (@ ((,uid ((> @ @) **)) **) @)
  1896. X        ) **)
  1897. X     :freq "all"))
  1898. X
  1899. X;;-----------------------------------------------------------
  1900. X
  1901. X
  1902. X
  1903. X
  1904. X;;===========================================================
  1905. X;;         Subling Entities Objects Attributes
  1906. X;;===========================================================
  1907. X
  1908. X
  1909. X(defun fe-jam.int.subs.ent.ob.attr (uid ob-name attr)
  1910. X  (cond
  1911. X   ;; assume entity and ob exists, insert new attr
  1912. X   ((vput attr `((~ "perc"
  1913. X            @2
  1914. X            (@
  1915. X             ((~ ,uid ((~ ,ob-name (^ @@)) **)) **)
  1916. X             @)
  1917. X            ) **)))
  1918. X  
  1919. X   ;; ob wasn't there, insert new ob with new attr
  1920. X   ((fe-jam.int.subs.ent.ob uid `(,ob-name (,attr))))
  1921. X   ))
  1922. X
  1923. X;;-----------------------------------------------------------
  1924. X
  1925. X;; attr is ("attr-name" attr-val)
  1926. X(defun fe-put.int.subs.ent.ob.attr (uid ob-name attr)
  1927. X  (cond
  1928. X   ;; assume the ent, ob and attr exist, swap in new attr
  1929. X   ((car (vput attr `((~ "perc"
  1930. X             @2
  1931. X             (@ 
  1932. X              ((~ ,uid ((~ ,ob-name (> (,(car attr) @) **)) **)) **)
  1933. X              @)
  1934. X             ) **))))
  1935. X
  1936. X   ;; attr wasn't there, insert new attr
  1937. X   ((fe-jam.int.subs.ent.ob.attr uid ob-name attr))
  1938. X   ))
  1939. X   
  1940. X;;-----------------------------------------------------------
  1941. X
  1942. X;; pass uid, ob-num, attr-name
  1943. X(defun fe-copy.int.subs.ent.ob.attr (uid ob-num attr-name &key (test-time nil))
  1944. X  (car (vcopy `(("perc"
  1945. X         @2
  1946. X         (@
  1947. X          ((,uid ((,ob-num (> (,attr-name @) **)) **)) **)
  1948. X          @)
  1949. X         ) **)
  1950. X          :test-time test-time)))
  1951. X
  1952. X;;-----------------------------------------------------------
  1953. X
  1954. X;; pass uid, ob-num, attr-name
  1955. X(defun fe-xtrct.int.subs.ent.ob.attr (uid ob-num attr-name)
  1956. X  (car (vget `(("perc"
  1957. X        @2
  1958. X        (@
  1959. X         ((,uid ((,ob-num (> (,attr-name @) **)) **)) **)
  1960. X         @)
  1961. X        ) **))))
  1962. X
  1963. X;;-----------------------------------------------------------
  1964. X
  1965. X;; pass uid, ob-num, attr-name
  1966. X(defun fe-get.int.subs.ent.ob.attr (uid ob-num attr-name)
  1967. X  (car (vput "%" `((~ "perc"
  1968. X              @2
  1969. X              (@
  1970. X               ((~ ,uid ((~ ,ob-num ((~ ,attr-name > @) **)) **)) **)
  1971. X               @)
  1972. X              ) **))))
  1973. X
  1974. X;;-----------------------------------------------------------
  1975. X
  1976. X
  1977. X
  1978. X;;===========================================================
  1979. X;;    Subling Entities Objects Attributes - Complex
  1980. X;;===========================================================
  1981. X
  1982. X;; pass uid and ob, return attr-list
  1983. X(defun fe-copy.int.subs.ent.ob.attr.names (uid ob-name)
  1984. X  (vcopy `(("perc"
  1985. X        @2
  1986. X        (@
  1987. X         ((,uid ((,ob-name ((> @ @) **)) **)) **)
  1988. X         @)
  1989. X        ) **)
  1990. X     :freq "all"))
  1991. X
  1992. X;;-----------------------------------------------------------
  1993. X
  1994. X;; pass attr, return values of all objects of all sibs
  1995. X(defun fe-copy.int.subs.attr.vals (attr-name)
  1996. X  (vcopy `(("perc"
  1997. X        @2
  1998. X        (@
  1999. X         ((@ ((@ ((,attr-name > @) **)) **)) **)
  2000. X         @)
  2001. X        ) **)
  2002. X     :freq "all"))
  2003. X
  2004. X;;-----------------------------------------------------------
  2005. X
  2006. X;; pass uid, ob-num, attr-name
  2007. X(defun fe-copy.int.subs.ent.ob.attr.val (uid ob-num attr-name)
  2008. X  (car (vcopy `(("perc"
  2009. X         @2
  2010. X         (@
  2011. X          ((,uid ((,ob-num ((,attr-name > @) **)) **)) **)
  2012. X          @)
  2013. X         ) **))))
  2014. X
  2015. X;;-----------------------------------------------------------
  2016. X
  2017. X
  2018. X
  2019. X
  2020. X
  2021. X;;===========================================================
  2022. X;;               Filters
  2023. X;;===========================================================
  2024. X
  2025. X(defun fe-put.int.fltrs (fltr)
  2026. X  (vput fltr '((~ "perc"
  2027. X          @2
  2028. X          (@2 > @)) **)))
  2029. X
  2030. X;;-----------------------------------------------------------
  2031. X
  2032. X(defun fe-copy.int.fltrs (&key (test-time nil))
  2033. X  (car (vcopy '(("perc"
  2034. X         @2
  2035. X         (@2 > @)) **)
  2036. X          :test-time test-time)))
  2037. X
  2038. X;;-----------------------------------------------------------
  2039. X
  2040. X(defun fe-xtrct.int.fltrs ()
  2041. X  (vget '(("perc"
  2042. X       @2
  2043. X       (@2 (> @@))) **)))
  2044. X
  2045. X;;-----------------------------------------------------------
  2046. X
  2047. X(defun fe-get.int.fltrs ()
  2048. X  (car (vput "%" '((~ "perc"
  2049. X              @2
  2050. X              (@2 > @)) **))))
  2051. X
  2052. X;;-----------------------------------------------------------
  2053. X
  2054. X
  2055. X
  2056. X;;===========================================================
  2057. X;;               Fltrs Entities
  2058. X;;===========================================================
  2059. X
  2060. X(defun fe-jam.int.fltrs.ent (ent)
  2061. X  (vput ent '((~ "perc"
  2062. X         @2
  2063. X         (@2 (^ @@))) **)))
  2064. X
  2065. X;;-----------------------------------------------------------
  2066. X
  2067. X;; an ent is: (uid (ob-list))
  2068. X(defun fe-put.int.fltrs.ent (ent)
  2069. X  (cond
  2070. X
  2071. X   ;; assume the ent exists, swap in the new ent
  2072. X   ((car (vput ent `((~ "perc"
  2073. X            @2
  2074. X            (@2 (> (,(car ent) @) **))
  2075. X            ) **))))
  2076. X
  2077. X   ;; ent didn't exist, insert new ent
  2078. X   ((fe-jam.int.fltrs.ent ent))
  2079. X   ))
  2080. X              
  2081. X;;-----------------------------------------------------------
  2082. X
  2083. X(defun fe-copy.int.fltrs.ent (uid &key (test-time nil))
  2084. X  (car (vcopy `(("perc"
  2085. X         @2
  2086. X         (@2 (> (,uid @) **))
  2087. X         ) **)
  2088. X          :test-time test-time)))
  2089. X
  2090. X;;-----------------------------------------------------------
  2091. X
  2092. X(defun fe-xtrct.int.fltrs.ent (uid)
  2093. X  (car (vget `(("perc"
  2094. X        @2
  2095. X        (@2 (> (,uid @) **))
  2096. X        ) **))))
  2097. X
  2098. X;;-----------------------------------------------------------
  2099. X
  2100. X(defun fe-get.int.fltrs.ent (uid)
  2101. X  (car (vput "%" `((~ "perc"
  2102. X              @2
  2103. X              (@2 ((~ ,uid > @) **))
  2104. X              ) **))))
  2105. X
  2106. X;;-----------------------------------------------------------
  2107. X
  2108. X
  2109. X
  2110. X
  2111. X;;===========================================================
  2112. X;;          Internal Entity Filter Processing
  2113. X;;===========================================================
  2114. X
  2115. X
  2116. X;;-----------------------------------------------------------
  2117. X
  2118. X(defun fe-fltr.int.subs (uid &key (test-time nil))
  2119. X  (delete uid
  2120. X      (fe-copy.int.subs :test-time test-time)
  2121. X      :test (lambda (x y) (equal x (car y)))))
  2122. X  
  2123. X;;-----------------------------------------------------------
  2124. X
  2125. X(defun fe-fltr.int.subs.uids (uid)
  2126. X  (delete uid 
  2127. X      (fe-copy.int.subs.uids)
  2128. X      :test 'equal))
  2129. X  
  2130. X;;-----------------------------------------------------------
  2131. X
  2132. X
  2133. X
  2134. X
  2135. END_OF_FILE
  2136. if test 16110 -ne `wc -c <'src/kernel_current/fern/fe_int.lsp'`; then
  2137.     echo shar: \"'src/kernel_current/fern/fe_int.lsp'\" unpacked with wrong size!
  2138. fi
  2139. # end of 'src/kernel_current/fern/fe_int.lsp'
  2140. fi
  2141. if test -f 'src/xlisp/xcore/c/xlobj.c' -a "${1}" != "-c" ; then 
  2142.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlobj.c'\"
  2143. else
  2144. echo shar: Extracting \"'src/xlisp/xcore/c/xlobj.c'\" \(16437 characters\)
  2145. sed "s/^X//" >'src/xlisp/xcore/c/xlobj.c' <<'END_OF_FILE'
  2146. X/* -*-C-*-
  2147. X********************************************************************************
  2148. X*
  2149. X* File:         xlobj.c
  2150. X* RCS:          $Header: xlobj.c,v 1.3 89/11/25 05:41:26 mayer Exp $
  2151. X* Description:  xlisp object functions
  2152. X* Author:       David Michael Betz
  2153. X* Created:      
  2154. X* Modified:     Sat Nov 25 05:41:13 1989 (Niels Mayer) mayer@hplnpm
  2155. X* Language:     C
  2156. X* Package:      N/A
  2157. X* Status:       X11r4 contrib tape release
  2158. X*
  2159. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  2160. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  2161. X*
  2162. X* Permission to use, copy, modify, distribute, and sell this software and its
  2163. X* documentation for any purpose is hereby granted without fee, provided that
  2164. X* the above copyright notice appear in all copies and that both that
  2165. X* copyright notice and this permission notice appear in supporting
  2166. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  2167. X* used in advertising or publicity pertaining to distribution of the software
  2168. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  2169. X* make no representations about the suitability of this software for any
  2170. X* purpose. It is provided "as is" without express or implied warranty.
  2171. X*
  2172. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  2173. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  2174. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  2175. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  2176. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  2177. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  2178. X* PERFORMANCE OF THIS SOFTWARE.
  2179. X*
  2180. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  2181. X* 
  2182. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  2183. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  2184. X*
  2185. X********************************************************************************
  2186. X*/
  2187. Xstatic char rcs_identity[] = "@(#)$Header: xlobj.c,v 1.3 89/11/25 05:41:26 mayer Exp $";
  2188. X
  2189. X
  2190. X#include "xlisp.h"
  2191. X
  2192. X/* external variables */
  2193. Xextern LVAL xlenv,xlfenv,xlvalue;
  2194. Xextern LVAL s_stdout,s_stderr,s_lambda;
  2195. Xextern LVAL s_send;/*91Jun15jsp*/
  2196. X
  2197. X/* local variables *//* 90Nov28 jsp exported READ ONLY! */
  2198. XLVAL s_self,k_new,k_isnew;/*JSP*/
  2199. XLVAL cls_class,cls_object;/*JSP*/
  2200. X
  2201. X/* forward declarations */
  2202. XFORWARD LVAL entermsg();
  2203. XFORWARD LVAL x_sendmsg();
  2204. XFORWARD LVAL evmethod();
  2205. X
  2206. X/* Include hybrid-class functions: *//* JSP */
  2207. X#define MODULE_XLOBJ_C_GLOBALS
  2208. X#include "../../xmodules.h"
  2209. X#undef MODULE_XLOBJ_C_GLOBALS
  2210. X
  2211. X/* xsend - send a message to an object */
  2212. XLVAL xsend()
  2213. X{
  2214. X    LVAL obj;
  2215. X    obj = xlgaobject();
  2216. X    return (x_sendmsg(obj,getclass(obj),xlgasymbol()));
  2217. X}
  2218. X
  2219. X/* xsendsuper - send a message to the superclass of an object */
  2220. XLVAL xsendsuper()
  2221. X{
  2222. X    LVAL env,p;
  2223. X    for (env = xlenv; env; env = cdr(env))
  2224. X    if ((p = car(env)) && objectp(car(p)))
  2225. X        return (x_sendmsg(car(p),
  2226. X                getivar(cdr(p),SUPERCLASS),
  2227. X                xlgasymbol()));
  2228. X    xlfail("not in a method");
  2229. X}
  2230. X
  2231. X/* xlclass - define a class */
  2232. XLVAL xlclass(name,vcnt)
  2233. X  char *name; int vcnt;
  2234. X{
  2235. X    LVAL sym,cls;
  2236. X
  2237. X    /* create the class */
  2238. X    sym = xlenter(name);
  2239. X    cls = newobject(cls_class,CLASSSIZE);
  2240. X    setvalue(sym,cls);
  2241. X
  2242. X    /* set the instance variable counts */
  2243. X    setivar(cls,IVARCNT,cvfixnum((FIXTYPE)vcnt));
  2244. X    setivar(cls,IVARTOTAL,cvfixnum((FIXTYPE)vcnt));
  2245. X
  2246. X    /* set the superclass to 'Object' */
  2247. X    setivar(cls,SUPERCLASS,cls_object);
  2248. X
  2249. X    /* return the new class */
  2250. X    return (cls);
  2251. X}
  2252. X
  2253. X#ifdef PROVIDE_WINTERP
  2254. X/* xlclass_p -- check if object is a class object as created by xlclass() */
  2255. Xint xlclass_p(o_class)
  2256. X     LVAL o_class;        /* assume type==OBJECT */
  2257. X{
  2258. X  return (getclass(o_class) == cls_class);
  2259. X}
  2260. X#endif
  2261. X
  2262. X/* xladdivar - enter an instance variable */
  2263. Xxladdivar(cls,var)
  2264. X  LVAL cls; char *var;
  2265. X{
  2266. X    setivar(cls,IVARS,cons(xlenter(var),getivar(cls,IVARS)));
  2267. X}
  2268. X
  2269. X/* xladdmsg - add a message to a class */
  2270. Xxladdmsg(cls,msg,offset)
  2271. X  LVAL cls; char *msg; int offset;
  2272. X{
  2273. X    extern FUNDEF *funtab;
  2274. X    LVAL mptr;
  2275. X
  2276. X    /* enter the message selector */
  2277. X    mptr = entermsg(cls,xlenter(msg));
  2278. X
  2279. X    /* store the method for this message */
  2280. X    rplacd(mptr,cvsubr(funtab[offset].fd_subr,funtab[offset].fd_type,offset));
  2281. X}
  2282. X
  2283. X/* xlobgetvalue - get the value of an instance variable */
  2284. Xint xlobgetvalue(pair,sym,pval)
  2285. X  LVAL pair;  /* pair is from an xlenv environment frame.   */
  2286. X              /* car(pair) is an object.                    */
  2287. X              /* cdr(pair) a [maybe super-]class of object. */
  2288. X  LVAL sym;   /* Symbol whose value we're trying to locate. */
  2289. X  LVAL *pval; /* Return path for value.                     */
  2290. X{             /* Return TRUE if we find sym, else FALSE.    */
  2291. X    LVAL cls,names;
  2292. X    int ivtotal,n;
  2293. X
  2294. X    /* find the instance or class variable */
  2295. X    for (cls = cdr(pair); objectp(cls); cls = getivar(cls,SUPERCLASS)) {
  2296. X
  2297. X    /* check the instance variables */
  2298. X    names = getivar(cls,IVARS);
  2299. X    ivtotal = getivcnt(cls,IVARTOTAL);
  2300. X    for (n = ivtotal - getivcnt(cls,IVARCNT); n < ivtotal; ++n) {
  2301. X        if (car(names) == sym) {
  2302. X        *pval = getivar(car(pair),n);
  2303. X        return (TRUE);
  2304. X        }
  2305. X        names = cdr(names);
  2306. X    }
  2307. X
  2308. X    /* check the class variables */
  2309. X    names = getivar(cls,CVARS);
  2310. X    for (n = 0; consp(names); ++n) {
  2311. X        if (car(names) == sym) {
  2312. X        *pval = getelement(getivar(cls,CVALS),n);
  2313. X        return (TRUE);
  2314. X        }
  2315. X        names = cdr(names);
  2316. X    }
  2317. X    }
  2318. X
  2319. X    /* variable not found */
  2320. X    return (FALSE);
  2321. X}
  2322. X
  2323. X/* xlobsetvalue - set the value of an instance variable */
  2324. Xint xlobsetvalue(pair,sym,val)
  2325. X  LVAL pair,sym,val;
  2326. X{
  2327. X    LVAL cls,names;
  2328. X    int ivtotal,n;
  2329. X
  2330. X    /* find the instance or class variable */
  2331. X    for (cls = cdr(pair); objectp(cls); cls = getivar(cls,SUPERCLASS)) {
  2332. X
  2333. X    /* check the instance variables */
  2334. X    names = getivar(cls,IVARS);
  2335. X    ivtotal = getivcnt(cls,IVARTOTAL);
  2336. X    for (n = ivtotal - getivcnt(cls,IVARCNT); n < ivtotal; ++n) {
  2337. X        if (car(names) == sym) {
  2338. X        setivar(car(pair),n,val);
  2339. X        return (TRUE);
  2340. X        }
  2341. X        names = cdr(names);
  2342. X    }
  2343. X
  2344. X    /* check the class variables */
  2345. X    names = getivar(cls,CVARS);
  2346. X    for (n = 0; consp(names); ++n) {
  2347. X        if (car(names) == sym) {
  2348. X        setelement(getivar(cls,CVALS),n,val);
  2349. X        return (TRUE);
  2350. X        }
  2351. X        names = cdr(names);
  2352. X    }
  2353. X    }
  2354. X
  2355. X    /* variable not found */
  2356. X    return (FALSE);
  2357. X}
  2358. X
  2359. X/* obisnew - default 'isnew' method */
  2360. XLVAL obisnew()
  2361. X{
  2362. X    LVAL self;
  2363. X    self = xlgaobject();
  2364. X    xllastarg();
  2365. X    return (self);
  2366. X}
  2367. X
  2368. X/* obclass - get the class of an object */
  2369. XLVAL obclass()
  2370. X{
  2371. X    LVAL self;
  2372. X    self = xlgaobject();
  2373. X    xllastarg();
  2374. X    return (getclass(self));
  2375. X}
  2376. X
  2377. X/* obshow - show the instance variables of an object */
  2378. XLVAL obshow()
  2379. X{
  2380. X    LVAL self,fptr,cls,names;
  2381. X    int ivtotal,n;
  2382. X
  2383. X    /* get self and the file pointer */
  2384. X    self = xlgaobject();
  2385. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  2386. X    xllastarg();
  2387. X
  2388. X    /* get the object's class */
  2389. X    cls = getclass(self);
  2390. X
  2391. X    /* print the object and class */
  2392. X    xlputstr(fptr,"Object is ");
  2393. X    xlprint(fptr,self,TRUE);
  2394. X    xlputstr(fptr,", Class is ");
  2395. X    xlprint(fptr,cls,TRUE);
  2396. X    xlterpri(fptr);
  2397. X
  2398. X    /* print the object's instance variables */
  2399. X    for (; cls; cls = getivar(cls,SUPERCLASS)) {
  2400. X    names = getivar(cls,IVARS);
  2401. X    ivtotal = getivcnt(cls,IVARTOTAL);
  2402. X    for (n = ivtotal - getivcnt(cls,IVARCNT); n < ivtotal; ++n) {
  2403. X
  2404. X        xlputstr(fptr,"  ");
  2405. X        xlprint(fptr,car(names),TRUE);
  2406. X        xlputstr(fptr," = ");
  2407. X        xlprint(fptr,getivar(self,n),TRUE);
  2408. X        xlterpri(fptr);
  2409. X        names = cdr(names);
  2410. X    }
  2411. X    }
  2412. X
  2413. X    /* return the object */
  2414. X    return (self);
  2415. X}
  2416. X
  2417. X
  2418. X/* clnew - create a new object instance */
  2419. XLVAL clnew()
  2420. X{
  2421. X    LVAL self;
  2422. X    self = xlgaobject();
  2423. X
  2424. X/* Include hybrid-class functions: *//* JSP */
  2425. X#define MODULE_XLOBJ_C_CLNEW
  2426. X#include "../../xmodules.h"
  2427. X#undef MODULE_XLOBJ_C_CLNEW
  2428. X
  2429. X    return     (newobject( self,getivcnt(self,IVARTOTAL)));
  2430. X}
  2431. X
  2432. X/* clisnew - initialize a new class */
  2433. XLVAL clisnew()
  2434. X{
  2435. X    LVAL self,ivars,cvars,super;
  2436. X    int n;
  2437. X
  2438. X    /* get self, the ivars, cvars and superclass */
  2439. X    self = xlgaobject();
  2440. X    ivars = xlgalist();
  2441. X    cvars = (moreargs() ? xlgalist() : NIL);
  2442. X    super = (moreargs() ? xlgaobject() : cls_object);
  2443. X    xllastarg();
  2444. X
  2445. X    /* store the instance and class variable lists and the superclass */
  2446. X    setivar(self,IVARS,ivars);
  2447. X    setivar(self,CVARS,cvars);
  2448. X    setivar(self,CVALS,(cvars ? newvector(listlength(cvars)) : NIL));
  2449. X    setivar(self,SUPERCLASS,super);
  2450. X
  2451. X    /* compute the instance variable count */
  2452. X    n = listlength(ivars);
  2453. X    setivar(self,IVARCNT,cvfixnum((FIXTYPE)n));
  2454. X    n += getivcnt(super,IVARTOTAL);
  2455. X    setivar(self,IVARTOTAL,cvfixnum((FIXTYPE)n));
  2456. X
  2457. X    /* return the new class object */
  2458. X    return (self);
  2459. X}
  2460. X
  2461. X/* clanswer - define a method for answering a message */
  2462. XLVAL clanswer()
  2463. X{
  2464. X    LVAL self,msg,fargs,code,mptr;
  2465. X
  2466. X    /* message symbol, formal argument list and code */
  2467. X    self = xlgaobject();
  2468. X    msg = xlgasymbol();
  2469. X    fargs = xlgalist();
  2470. X    code = xlgalist();
  2471. X    xllastarg();
  2472. X
  2473. X    /* make a new message list entry */
  2474. X    mptr = entermsg(self,msg);
  2475. X
  2476. X    /* set up the message node */
  2477. X    xlprot1(fargs);
  2478. X    fargs = cons(s_self,fargs); /* add 'self' as the first argument */
  2479. X    rplacd(mptr,xlclose(msg,s_lambda,fargs,code,xlenv,xlfenv));    /* changed by NPM -- pass in lexical and functional environment */
  2480. X    xlpop();
  2481. X
  2482. X    /* return the object */
  2483. X    return (self);
  2484. X}
  2485. X
  2486. X/* entermsg - add a message to a class */
  2487. XLOCAL LVAL entermsg(cls,msg)
  2488. X  LVAL cls,msg;
  2489. X{
  2490. X    LVAL lptr,mptr;
  2491. X
  2492. X    /* look up the message */
  2493. X    for (lptr = getivar(cls,MESSAGES); lptr; lptr = cdr(lptr))
  2494. X    if (car(mptr = car(lptr)) == msg)
  2495. X        return (mptr);
  2496. X
  2497. X    /* allocate a new message entry if one wasn't found */
  2498. X    xlsave1(mptr);
  2499. X    mptr = consa(msg);
  2500. X    setivar(cls,MESSAGES,cons(mptr,getivar(cls,MESSAGES)));
  2501. X    xlpop();
  2502. X
  2503. X    /* return the symbol node */
  2504. X    return (mptr);
  2505. X}
  2506. X
  2507. X/* xsendmsgN - external entry to send a message to an object, N args: */
  2508. XLVAL xsendmsgN(obj,sym,args,arg1,arg2,arg3) /*Created 91Jun15jsp*/
  2509. XLVAL obj,sym;
  2510. Xint args;
  2511. XLVAL arg1,arg2,arg3;
  2512. X{
  2513. X    /* This is basically ripped off from the SUBR case of xleval.c:evform(). */
  2514. X    LVAL  val;
  2515. X    LVAL *argv;
  2516. X    int argc;
  2517. X
  2518. X    xllastarg(); /* Make sure nothing on stack */
  2519. X    argv = xlargv;
  2520. X    argc = xlargc;
  2521. X
  2522. X    args+= 2;    /* Count obj and sym as args.   */
  2523. X    {   /* Begin inlineed simplified pushargs() */
  2524. X    /* build a new argument stack frame */
  2525. X    LVAL*newfp = xlsp;
  2526. X    pusharg(cvfixnum((FIXTYPE)(newfp - xlfp)));
  2527. X    pusharg(xlgetfunction(s_send));
  2528. X    pusharg(cvfixnum((FIXTYPE)args)); /* argc(ount) */
  2529. X    pusharg( obj );    /* Push message recipient.           */
  2530. X    pusharg( sym );    /* Push message selector.            */
  2531. X    if (args > 2) pusharg( arg1 );
  2532. X    if (args > 3) pusharg( arg2 );
  2533. X    if (args > 4) pusharg( arg3 );
  2534. X    xlfp = newfp;    /* Establish the new stack frame.    */
  2535. X        xlargc = args;    /* Remember the number of arguments. */
  2536. X    } /* End   inlineed simplified pushargs() */
  2537. X
  2538. X    xlargv = xlfp + 3;
  2539. X    val = xsend();
  2540. X    xlsp = xlfp;
  2541. X    xlfp = xlfp - (int)getfixnum(*xlfp);
  2542. X    xlargv = argv;
  2543. X    xlargc = argc;
  2544. X    return val;
  2545. X}
  2546. X/* xsendmsg0 - external entry to send a message to an object, no arg */
  2547. XLVAL xsendmsg0(obj,sym) /*Created 91Jun16jsp*/
  2548. XLVAL obj,sym;
  2549. X{
  2550. X    return xsendmsgN(obj,sym,0,NIL,NIL,NIL);
  2551. X}
  2552. X/* xsendmsg1 - external entry to send a message to an object, 1 arg */
  2553. XLVAL xsendmsg1(obj,sym,arg1) /*Created 91Jun15jsp*/
  2554. XLVAL obj,sym,arg1;
  2555. X{
  2556. X    return xsendmsgN(obj,sym,1,arg1,NIL,NIL);
  2557. X}
  2558. X/* xsendmsg2 - external entry to send a message to an object, 2 args */
  2559. XLVAL xsendmsg2(obj,sym,arg1,arg2) /*Created 91Jun16jsp*/
  2560. XLVAL obj,sym,arg1,arg2;
  2561. X{
  2562. X    return xsendmsgN(obj,sym,2,arg1,arg2,NIL);
  2563. X}
  2564. X/* xsendmsg3 - external entry to send a message to an object, 3 args */
  2565. XLVAL xsendmsg3(obj,sym,arg1,arg2,arg3) /*Created 91Jun16jsp*/
  2566. XLVAL obj,sym,arg1,arg2,arg3;
  2567. X{
  2568. X    return xsendmsgN(obj,sym,3,arg1,arg2,arg3);
  2569. X}
  2570. X
  2571. X/* x_sendmsg - internal entry to send a message to an object */
  2572. XLOCAL LVAL x_sendmsg(obj,cls,sym)
  2573. X  LVAL obj,cls,sym;
  2574. X{
  2575. X    LVAL msg,msgcls,method,val,p;
  2576. X
  2577. X    /* look for the message in the class or superclasses */
  2578. X    for (msgcls = cls; msgcls; ) {
  2579. X
  2580. X    /* lookup the message in this class */
  2581. X    for (p = getivar(msgcls,MESSAGES); p; p = cdr(p))
  2582. X        if ((msg = car(p)) && car(msg) == sym)
  2583. X        goto send_message;
  2584. X
  2585. X    /* look in class's superclass */
  2586. X    msgcls = getivar(msgcls,SUPERCLASS);
  2587. X    }
  2588. X
  2589. X    /* message not found */
  2590. X    xlerror("no method for this message",sym);
  2591. X
  2592. Xsend_message:
  2593. X
  2594. X    /* insert the value for 'self' (overwrites message selector) */
  2595. X    *--xlargv = obj;
  2596. X    ++xlargc;
  2597. X    
  2598. X    /* invoke the method */
  2599. X    if ((method = cdr(msg)) == NULL)
  2600. X    xlerror("bad method",method);
  2601. X    switch (ntype(method)) {
  2602. X    case SUBR:
  2603. X    val = (*getsubr(method))();
  2604. X    break;
  2605. X    case CLOSURE:
  2606. X    if (gettype(method) != s_lambda)
  2607. X        xlerror("bad method",method);
  2608. X    val = evmethod(obj,msgcls,method);
  2609. X    break;
  2610. X    default:
  2611. X    xlerror("bad method",method);
  2612. X    }
  2613. X
  2614. X    /* after creating an object, send it the ":isnew" message */
  2615. X    if (car(msg) == k_new && val) {
  2616. X    xlprot1(val);
  2617. X    x_sendmsg(val,getclass(val),k_isnew);
  2618. X    xlpop();
  2619. X    }
  2620. X    
  2621. X    /* return the result value */
  2622. X    return (val);
  2623. X}
  2624. X
  2625. X/* evmethod - evaluate a method */
  2626. XLOCAL LVAL evmethod(obj,msgcls,method)
  2627. X  LVAL obj,msgcls,method;
  2628. X{
  2629. X    LVAL oldenv,oldfenv,cptr,name,val;
  2630. X    CONTEXT cntxt;
  2631. X
  2632. X    /* protect some pointers */
  2633. X    xlstkcheck(3);
  2634. X    xlsave(oldenv);
  2635. X    xlsave(oldfenv);
  2636. X    xlsave(cptr);
  2637. X
  2638. X    /* create an 'object' stack entry and a new environment frame */
  2639. X    oldenv = xlenv;
  2640. X    oldfenv = xlfenv;
  2641. X    xlenv = cons(cons(obj,msgcls),xlgetenv(method));
  2642. X    xlenv = xlframe(xlenv);
  2643. X    xlfenv = getfenv(method);
  2644. X
  2645. X    /* bind the formal parameters */
  2646. X    xlabind(method,xlargc,xlargv);
  2647. X
  2648. X    /* set up the implicit block */
  2649. X    if (name = getname(method))
  2650. X    xlbegin(&cntxt,CF_RETURN,name);
  2651. X
  2652. X    /* execute the block */
  2653. X    if (name && xlsetjmp(cntxt.c_jmpbuf))
  2654. X    val = xlvalue;
  2655. X    else
  2656. X    for (cptr = getbody(method); consp(cptr); cptr = cdr(cptr))
  2657. X        val = xleval(car(cptr));
  2658. X
  2659. X    /* finish the block context */
  2660. X    if (name)
  2661. X    xlend(&cntxt);
  2662. X
  2663. X    /* restore the environment */
  2664. X    xlenv = oldenv;
  2665. X    xlfenv = oldfenv;
  2666. X
  2667. X    /* restore the stack */
  2668. X    xlpopn(3);
  2669. X
  2670. X    /* return the result value */
  2671. X    return (val);
  2672. X}
  2673. X
  2674. X/* getivcnt - get the number of instance variables for a class */
  2675. Xint getivcnt(cls,ivar)
  2676. X  LVAL cls; int ivar;
  2677. X{
  2678. X    LVAL cnt;
  2679. X    if ((cnt = getivar(cls,ivar)) == NIL || !fixp(cnt))
  2680. X    xlfail("bad value for instance variable count");
  2681. X    return ((int)getfixnum(cnt));
  2682. X}
  2683. X
  2684. X/* listlength - find the length of a list */
  2685. XLOCAL int listlength(list)
  2686. X  LVAL list;
  2687. X{
  2688. X    int len;
  2689. X    for (len = 0; consp(list); len++)
  2690. X    list = cdr(list);
  2691. X    return (len);
  2692. X}
  2693. X
  2694. X/* obsymbols - initialize symbols */
  2695. Xobsymbols()
  2696. X{
  2697. X    /* enter the object related symbols */
  2698. X    s_self  = xlenter("SELF");
  2699. X    k_new   = xlenter(":NEW");
  2700. X    k_isnew = xlenter(":ISNEW");
  2701. X
  2702. X    /* get the Object and Class symbol values */
  2703. X    cls_object = getvalue(xlenter("OBJECT"));
  2704. X    cls_class  = getvalue(xlenter("CLASS"));
  2705. X
  2706. X/* Include hybrid-class functions: *//* JSP */
  2707. X#define MODULE_XLOBJ_C_OBSYMBOLS
  2708. X#include "../../xmodules.h"
  2709. X#undef MODULE_XLOBJ_C_OBSYMBOLS
  2710. X}
  2711. X
  2712. X/* xloinit - object function initialization routine */
  2713. Xxloinit()
  2714. X{
  2715. X    /* create the 'Class' object */
  2716. X    cls_class = xlclass("CLASS",CLASSSIZE);
  2717. X    setelement(cls_class,0,cls_class);
  2718. X
  2719. X    /* create the 'Object' object */
  2720. X    cls_object = xlclass("OBJECT",0);
  2721. X
  2722. X    /* finish initializing 'class' */
  2723. X    setivar(cls_class,SUPERCLASS,cls_object);
  2724. X    xladdivar(cls_class,"IVARTOTAL");    /* ivar number 6 */
  2725. X    xladdivar(cls_class,"IVARCNT");    /* ivar number 5 */
  2726. X    xladdivar(cls_class,"SUPERCLASS");    /* ivar number 4 */
  2727. X    xladdivar(cls_class,"CVALS");    /* ivar number 3 */
  2728. X    xladdivar(cls_class,"CVARS");    /* ivar number 2 */
  2729. X    xladdivar(cls_class,"IVARS");    /* ivar number 1 */
  2730. X    xladdivar(cls_class,"MESSAGES");    /* ivar number 0 */
  2731. X    xladdmsg(cls_class,":NEW",FT_CLNEW);
  2732. X    xladdmsg(cls_class,":ISNEW",FT_CLISNEW);
  2733. X    xladdmsg(cls_class,":ANSWER",FT_CLANSWER);
  2734. X
  2735. X    /* finish initializing 'object' */
  2736. X    setivar(cls_object,SUPERCLASS,NIL);
  2737. X    xladdmsg(cls_object,":ISNEW",FT_OBISNEW);
  2738. X    xladdmsg(cls_object,":CLASS",FT_OBCLASS);
  2739. X    xladdmsg(cls_object,":SHOW",FT_OBSHOW);
  2740. X
  2741. X/* Include hybrid-class functions: *//* JSP */
  2742. X#define MODULE_XLOBJ_C_XLOINIT
  2743. X#include "../../xmodules.h"
  2744. X#undef MODULE_XLOBJ_C_XLOINIT
  2745. X}
  2746. X
  2747. END_OF_FILE
  2748. if test 16437 -ne `wc -c <'src/xlisp/xcore/c/xlobj.c'`; then
  2749.     echo shar: \"'src/xlisp/xcore/c/xlobj.c'\" unpacked with wrong size!
  2750. fi
  2751. # end of 'src/xlisp/xcore/c/xlobj.c'
  2752. fi
  2753. if test -f 'src/xlisp/xcore/c/xlstr.c' -a "${1}" != "-c" ; then 
  2754.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlstr.c'\"
  2755. else
  2756. echo shar: Extracting \"'src/xlisp/xcore/c/xlstr.c'\" \(15062 characters\)
  2757. sed "s/^X//" >'src/xlisp/xcore/c/xlstr.c' <<'END_OF_FILE'
  2758. X/* -*-C-*-
  2759. X********************************************************************************
  2760. X*
  2761. X* File:         xlstr.c
  2762. X* RCS:          $Header: xlstr.c,v 1.2 89/11/25 05:44:25 mayer Exp $
  2763. X* Description:  xlisp string and character built-in functions
  2764. X* Author:       David Michael Betz
  2765. X* Created:      
  2766. X* Modified:     Sat Nov 25 05:44:13 1989 (Niels Mayer) mayer@hplnpm
  2767. X* Language:     C
  2768. X* Package:      N/A
  2769. X* Status:       X11r4 contrib tape release
  2770. X*
  2771. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  2772. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  2773. X*
  2774. X* Permission to use, copy, modify, distribute, and sell this software and its
  2775. X* documentation for any purpose is hereby granted without fee, provided that
  2776. X* the above copyright notice appear in all copies and that both that
  2777. X* copyright notice and this permission notice appear in supporting
  2778. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  2779. X* used in advertising or publicity pertaining to distribution of the software
  2780. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  2781. X* make no representations about the suitability of this software for any
  2782. X* purpose. It is provided "as is" without express or implied warranty.
  2783. X*
  2784. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  2785. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  2786. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  2787. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  2788. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  2789. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  2790. X* PERFORMANCE OF THIS SOFTWARE.
  2791. X*
  2792. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  2793. X* 
  2794. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  2795. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  2796. X*
  2797. X********************************************************************************
  2798. X*/
  2799. Xstatic char rcs_identity[] = "@(#)$Header: xlstr.c,v 1.2 89/11/25 05:44:25 mayer Exp $";
  2800. X
  2801. X
  2802. X
  2803. X#include "xlisp.h"
  2804. X
  2805. X/* local definitions */
  2806. X#define fix(n)    cvfixnum((FIXTYPE)(n))
  2807. X#define TLEFT    1
  2808. X#define TRIGHT    2
  2809. X
  2810. X/* external variables */
  2811. Xextern LVAL k_start,k_end,k_1start,k_1end,k_2start,k_2end;
  2812. Xextern LVAL true;
  2813. Xextern char buf[];
  2814. X
  2815. X/* external procedures */
  2816. Xextern char *strcat();
  2817. X
  2818. X/* forward declarations */
  2819. XFORWARD LVAL strcompare();
  2820. XFORWARD LVAL chrcompare();
  2821. XFORWARD LVAL changecase();
  2822. XFORWARD LVAL trim();
  2823. X
  2824. X/* string comparision functions */
  2825. XLVAL xstrlss() { return (strcompare('<',FALSE)); } /* string< */
  2826. XLVAL xstrleq() { return (strcompare('L',FALSE)); } /* string<= */
  2827. XLVAL xstreql() { return (strcompare('=',FALSE)); } /* string= */
  2828. XLVAL xstrneq() { return (strcompare('#',FALSE)); } /* string/= */
  2829. XLVAL xstrgeq() { return (strcompare('G',FALSE)); } /* string>= */
  2830. XLVAL xstrgtr() { return (strcompare('>',FALSE)); } /* string> */
  2831. X
  2832. X/* string comparison functions (not case sensitive) */
  2833. XLVAL xstrilss() { return (strcompare('<',TRUE)); } /* string-lessp */
  2834. XLVAL xstrileq() { return (strcompare('L',TRUE)); } /* string-not-greaterp */
  2835. XLVAL xstrieql() { return (strcompare('=',TRUE)); } /* string-equal */
  2836. XLVAL xstrineq() { return (strcompare('#',TRUE)); } /* string-not-equal */
  2837. XLVAL xstrigeq() { return (strcompare('G',TRUE)); } /* string-not-lessp */
  2838. XLVAL xstrigtr() { return (strcompare('>',TRUE)); } /* string-greaterp */
  2839. X
  2840. X/* strcompare - compare strings */
  2841. XLOCAL LVAL strcompare(fcn,icase)
  2842. X  int fcn,icase;
  2843. X{
  2844. X    int start1,end1,start2,end2,ch1,ch2;
  2845. X    unsigned char *p1,*p2;
  2846. X    LVAL str1,str2;
  2847. X
  2848. X    /* get the strings */
  2849. X    str1 = xlgastring();
  2850. X    str2 = xlgastring();
  2851. X
  2852. X    /* get the substring specifiers */
  2853. X    getbounds(str1,k_1start,k_1end,&start1,&end1);
  2854. X    getbounds(str2,k_2start,k_2end,&start2,&end2);
  2855. X
  2856. X    /* setup the string pointers */
  2857. X    p1 = &getstring(str1)[start1];
  2858. X    p2 = &getstring(str2)[start2];
  2859. X
  2860. X    /* compare the strings */
  2861. X    for (; start1 < end1 && start2 < end2; ++start1,++start2) {
  2862. X    ch1 = *p1++;
  2863. X    ch2 = *p2++;
  2864. X    if (icase) {
  2865. X        if (isupper(ch1)) ch1 = tolower(ch1);
  2866. X        if (isupper(ch2)) ch2 = tolower(ch2);
  2867. X    }
  2868. X    if (ch1 != ch2)
  2869. X        switch (fcn) {
  2870. X        case '<':    return (ch1 < ch2 ? fix(start1) : NIL);
  2871. X        case 'L':    return (ch1 <= ch2 ? fix(start1) : NIL);
  2872. X        case '=':    return (NIL);
  2873. X        case '#':    return (fix(start1));
  2874. X        case 'G':    return (ch1 >= ch2 ? fix(start1) : NIL);
  2875. X        case '>':    return (ch1 > ch2 ? fix(start1) : NIL);
  2876. X        }
  2877. X    }
  2878. X
  2879. X    /* check the termination condition */
  2880. X    switch (fcn) {
  2881. X    case '<':    return (start1 >= end1 && start2 < end2 ? fix(start1) : NIL);
  2882. X    case 'L':    return (start1 >= end1 ? fix(start1) : NIL);
  2883. X    case '=':    return (start1 >= end1 && start2 >= end2 ? true : NIL);
  2884. X    case '#':    return (start1 >= end1 && start2 >= end2 ? NIL : fix(start1));
  2885. X    case 'G':    return (start2 >= end2 ? fix(start1) : NIL);
  2886. X    case '>':    return (start2 >= end2 && start1 < end1 ? fix(start1) : NIL);
  2887. X    }
  2888. X}
  2889. X
  2890. X/* case conversion functions */
  2891. XLVAL xupcase()   { return (changecase('U',FALSE)); }
  2892. XLVAL xdowncase() { return (changecase('D',FALSE)); }
  2893. X
  2894. X/* destructive case conversion functions */
  2895. XLVAL xnupcase()   { return (changecase('U',TRUE)); }
  2896. XLVAL xndowncase() { return (changecase('D',TRUE)); }
  2897. X
  2898. X/* changecase - change case */
  2899. XLOCAL LVAL changecase(fcn,destructive)
  2900. X  int fcn,destructive;
  2901. X{
  2902. X    unsigned char *srcp,*dstp;
  2903. X    int start,end,len,ch,i;
  2904. X    LVAL src,dst;
  2905. X
  2906. X    /* get the string */
  2907. X    src = xlgastring();
  2908. X
  2909. X    /* get the substring specifiers */
  2910. X    getbounds(src,k_start,k_end,&start,&end);
  2911. X    len = getslength(src) - 1;
  2912. X
  2913. X    /* make a destination string */
  2914. X    dst = (destructive ? src : newstring(len+1));
  2915. X
  2916. X    /* setup the string pointers */
  2917. X    srcp = getstring(src);
  2918. X    dstp = getstring(dst);
  2919. X
  2920. X    /* copy the source to the destination */
  2921. X    for (i = 0; i < len; ++i) {
  2922. X    ch = *srcp++;
  2923. X    if (i >= start && i < end)
  2924. X        switch (fcn) {
  2925. X        case 'U':    if (islower(ch)) ch = toupper(ch); break;
  2926. X        case 'D':    if (isupper(ch)) ch = tolower(ch); break;
  2927. X        }
  2928. X    *dstp++ = ch;
  2929. X    }
  2930. X    *dstp = '\0';
  2931. X
  2932. X    /* return the new string */
  2933. X    return (dst);
  2934. X}
  2935. X
  2936. X/* trim functions */
  2937. XLVAL xtrim()      { return (trim(TLEFT|TRIGHT)); }
  2938. XLVAL xlefttrim()  { return (trim(TLEFT)); }
  2939. XLVAL xrighttrim() { return (trim(TRIGHT)); }
  2940. X
  2941. X/* trim - trim character from a string */
  2942. XLOCAL LVAL trim(fcn)
  2943. X  int fcn;
  2944. X{
  2945. X    unsigned char *leftp,*rightp,*dstp;
  2946. X    LVAL bag,src,dst;
  2947. X
  2948. X    /* get the bag and the string */
  2949. X    bag = xlgastring();
  2950. X    src = xlgastring();
  2951. X    xllastarg();
  2952. X
  2953. X    /* setup the string pointers */
  2954. X    leftp = getstring(src);
  2955. X    rightp = leftp + getslength(src) - 2;
  2956. X
  2957. X    /* trim leading characters */
  2958. X    if (fcn & TLEFT)
  2959. X    while (leftp <= rightp && inbag(*leftp,bag))
  2960. X        ++leftp;
  2961. X
  2962. X    /* trim character from the right */
  2963. X    if (fcn & TRIGHT)
  2964. X    while (rightp >= leftp && inbag(*rightp,bag))
  2965. X        --rightp;
  2966. X
  2967. X    /* make a destination string and setup the pointer */
  2968. X    dst = newstring((int)(rightp-leftp+2));
  2969. X    dstp = getstring(dst);
  2970. X
  2971. X    /* copy the source to the destination */
  2972. X    while (leftp <= rightp)
  2973. X    *dstp++ = *leftp++;
  2974. X    *dstp = '\0';
  2975. X
  2976. X    /* return the new string */
  2977. X    return (dst);
  2978. X}
  2979. X
  2980. X/* getbounds - get the start and end bounds of a string */
  2981. XLOCAL getbounds(str,skey,ekey,pstart,pend)
  2982. X  LVAL str,skey,ekey; int *pstart,*pend;
  2983. X{
  2984. X    LVAL arg;
  2985. X    int len;
  2986. X
  2987. X    /* get the length of the string */
  2988. X    len = getslength(str) - 1;
  2989. X
  2990. X    /* get the starting index */
  2991. X    if (xlgkfixnum(skey,&arg)) {
  2992. X    *pstart = (int)getfixnum(arg);
  2993. X    if (*pstart < 0 || *pstart > len)
  2994. X        xlerror("string index out of bounds",arg);
  2995. X    }
  2996. X    else
  2997. X    *pstart = 0;
  2998. X
  2999. X    /* get the ending index */
  3000. X    if (xlgkfixnum(ekey,&arg)) {
  3001. X    *pend = (int)getfixnum(arg);
  3002. X    if (*pend < 0 || *pend > len)
  3003. X        xlerror("string index out of bounds",arg);
  3004. X    }
  3005. X    else
  3006. X    *pend = len;
  3007. X
  3008. X    /* make sure the start is less than or equal to the end */
  3009. X    if (*pstart > *pend)
  3010. X    xlerror("starting index error",cvfixnum((FIXTYPE)*pstart));
  3011. X}
  3012. X
  3013. X/* inbag - test if a character is in a bag */
  3014. XLOCAL int inbag(ch,bag)
  3015. X  int ch; LVAL bag;
  3016. X{
  3017. X    unsigned char *p;
  3018. X    for (p = getstring(bag); *p != '\0'; ++p)
  3019. X    if (*p == ch)
  3020. X        return (TRUE);
  3021. X    return (FALSE);
  3022. X}
  3023. X
  3024. X/* xstrcat - concatenate a bunch of strings */
  3025. XLVAL xstrcat()
  3026. X{
  3027. X    LVAL *saveargv,tmp,val;
  3028. X    unsigned char *str;
  3029. X    int saveargc,len;
  3030. X
  3031. X    /* save the argument list */
  3032. X    saveargv = xlargv;
  3033. X    saveargc = xlargc;
  3034. X
  3035. X    /* find the length of the new string */
  3036. X    for (len = 0; moreargs(); ) {
  3037. X    tmp = xlgastring();
  3038. X    len += (int)getslength(tmp) - 1;
  3039. X    }
  3040. X
  3041. X    /* create the result string */
  3042. X    val = newstring(len+1);
  3043. X    str = getstring(val);
  3044. X
  3045. X    /* restore the argument list */
  3046. X    xlargv = saveargv;
  3047. X    xlargc = saveargc;
  3048. X    
  3049. X    /* combine the strings */
  3050. X    for (*str = '\0'; moreargs(); ) {
  3051. X    tmp = nextarg();
  3052. X    strcat(str,getstring(tmp));
  3053. X    }
  3054. X
  3055. X    /* return the new string */
  3056. X    return (val);
  3057. X}
  3058. X
  3059. X/* xsubseq - return a subsequence */
  3060. XLVAL xsubseq()
  3061. X{
  3062. X    unsigned char *srcp,*dstp;
  3063. X    int start,end,len;
  3064. X    LVAL src,dst;
  3065. X
  3066. X    /* get string and starting and ending positions */
  3067. X    src = xlgastring();
  3068. X
  3069. X    /* get the starting position */
  3070. X    dst = xlgafixnum(); start = (int)getfixnum(dst);
  3071. X    if (start < 0 || start > getslength(src) - 1)
  3072. X    xlerror("string index out of bounds",dst);
  3073. X
  3074. X    /* get the ending position */
  3075. X    if (moreargs()) {
  3076. X    dst = xlgafixnum(); end = (int)getfixnum(dst);
  3077. X    if (end < 0 || end > getslength(src) - 1)
  3078. X        xlerror("string index out of bounds",dst);
  3079. X    }
  3080. X    else
  3081. X    end = getslength(src) - 1;
  3082. X    xllastarg();
  3083. X
  3084. X    /* setup the source pointer */
  3085. X    srcp = getstring(src) + start;
  3086. X    len = end - start;
  3087. X
  3088. X    /* make a destination string and setup the pointer */
  3089. X    dst = newstring(len+1);
  3090. X    dstp = getstring(dst);
  3091. X
  3092. X    /* copy the source to the destination */
  3093. X    while (--len >= 0)
  3094. X    *dstp++ = *srcp++;
  3095. X    *dstp = '\0';
  3096. X
  3097. X    /* return the substring */
  3098. X    return (dst);
  3099. X}
  3100. X
  3101. X/* xstring - return a string consisting of a single character */
  3102. XLVAL xstring()
  3103. X{
  3104. X    LVAL arg;
  3105. X
  3106. X    /* get the argument */
  3107. X    arg = xlgetarg();
  3108. X    xllastarg();
  3109. X
  3110. X    /* make sure its not NIL */
  3111. X    if (null(arg))
  3112. X    xlbadtype(arg);
  3113. X
  3114. X    /* check the argument type */
  3115. X    switch (ntype(arg)) {
  3116. X    case STRING:
  3117. X    return (arg);
  3118. X    case SYMBOL:
  3119. X    return (getpname(arg));
  3120. X    case CHAR:
  3121. X    buf[0] = (int)getchcode(arg);
  3122. X    buf[1] = '\0';
  3123. X    return (cvstring(buf));
  3124. X    default:
  3125. X    xlbadtype(arg);
  3126. X    }
  3127. X}
  3128. X
  3129. X/* xchar - extract a character from a string */
  3130. XLVAL xchar()
  3131. X{
  3132. X    LVAL str,num;
  3133. X    int n;
  3134. X
  3135. X    /* get the string and the index */
  3136. X    str = xlgastring();
  3137. X    num = xlgafixnum();
  3138. X    xllastarg();
  3139. X
  3140. X    /* range check the index */
  3141. X    if ((n = (int)getfixnum(num)) < 0 || n >= getslength(str) - 1)
  3142. X    xlerror("index out of range",num);
  3143. X
  3144. X    /* return the character */
  3145. X    return (cvchar(getstring(str)[n]));
  3146. X}
  3147. X
  3148. X/* xcharint - convert an integer to a character */
  3149. XLVAL xcharint()
  3150. X{
  3151. X    LVAL arg;
  3152. X    arg = xlgachar();
  3153. X    xllastarg();
  3154. X    return (cvfixnum((FIXTYPE)getchcode(arg)));
  3155. X}
  3156. X
  3157. X/* xintchar - convert a character to an integer */
  3158. XLVAL xintchar()
  3159. X{
  3160. X    LVAL arg;
  3161. X    arg = xlgafixnum();
  3162. X    xllastarg();
  3163. X    return (cvchar((int)getfixnum(arg)));
  3164. X}
  3165. X
  3166. X/* xuppercasep - built-in function 'upper-case-p' */
  3167. XLVAL xuppercasep()
  3168. X{
  3169. X    int ch;
  3170. X    ch = getchcode(xlgachar());
  3171. X    xllastarg();
  3172. X    return (isupper(ch) ? true : NIL);
  3173. X}
  3174. X
  3175. X/* xlowercasep - built-in function 'lower-case-p' */
  3176. XLVAL xlowercasep()
  3177. X{
  3178. X    int ch;
  3179. X    ch = getchcode(xlgachar());
  3180. X    xllastarg();
  3181. X    return (islower(ch) ? true : NIL);
  3182. X}
  3183. X
  3184. X/* xbothcasep - built-in function 'both-case-p' */
  3185. XLVAL xbothcasep()
  3186. X{
  3187. X    int ch;
  3188. X    ch = getchcode(xlgachar());
  3189. X    xllastarg();
  3190. X    return (isupper(ch) || islower(ch) ? true : NIL);
  3191. X}
  3192. X
  3193. X/* xdigitp - built-in function 'digit-char-p' */
  3194. XLVAL xdigitp()
  3195. X{
  3196. X    int ch;
  3197. X    ch = getchcode(xlgachar());
  3198. X    xllastarg();
  3199. X    return (isdigit(ch) ? cvfixnum((FIXTYPE)(ch - '0')) : NIL);
  3200. X}
  3201. X
  3202. X/* xcharcode - built-in function 'char-code' */
  3203. XLVAL xcharcode()
  3204. X{
  3205. X    int ch;
  3206. X    ch = getchcode(xlgachar());
  3207. X    xllastarg();
  3208. X    return (cvfixnum((FIXTYPE)ch));
  3209. X}
  3210. X
  3211. X/* xcodechar - built-in function 'code-char' */
  3212. XLVAL xcodechar()
  3213. X{
  3214. X    LVAL arg;
  3215. X    int ch;
  3216. X    arg = xlgafixnum(); ch = getfixnum(arg);
  3217. X    xllastarg();
  3218. X    return (ch >= 0 && ch <= 127 ? cvchar(ch) : NIL);
  3219. X}
  3220. X
  3221. X/* xchupcase - built-in function 'char-upcase' */
  3222. XLVAL xchupcase()
  3223. X{
  3224. X    LVAL arg;
  3225. X    int ch;
  3226. X    arg = xlgachar(); ch = getchcode(arg);
  3227. X    xllastarg();
  3228. X    return (islower(ch) ? cvchar(toupper(ch)) : arg);
  3229. X}
  3230. X
  3231. X/* xchdowncase - built-in function 'char-downcase' */
  3232. XLVAL xchdowncase()
  3233. X{
  3234. X    LVAL arg;
  3235. X    int ch;
  3236. X    arg = xlgachar(); ch = getchcode(arg);
  3237. X    xllastarg();
  3238. X    return (isupper(ch) ? cvchar(tolower(ch)) : arg);
  3239. X}
  3240. X
  3241. X/* xdigitchar - built-in function 'digit-char' */
  3242. XLVAL xdigitchar()
  3243. X{
  3244. X    LVAL arg;
  3245. X    int n;
  3246. X    arg = xlgafixnum(); n = getfixnum(arg);
  3247. X    xllastarg();
  3248. X    return (n >= 0 && n <= 9 ? cvchar(n + '0') : NIL);
  3249. X}
  3250. X
  3251. X/* xalphanumericp - built-in function 'alphanumericp' */
  3252. XLVAL xalphanumericp()
  3253. X{
  3254. X    int ch;
  3255. X    ch = getchcode(xlgachar());
  3256. X    xllastarg();
  3257. X    return (isupper(ch) || islower(ch) || isdigit(ch) ? true : NIL);
  3258. X}
  3259. X
  3260. X/* character comparision functions */
  3261. XLVAL xchrlss() { return (chrcompare('<',FALSE)); } /* char< */
  3262. XLVAL xchrleq() { return (chrcompare('L',FALSE)); } /* char<= */
  3263. XLVAL xchreql() { return (chrcompare('=',FALSE)); } /* char= */
  3264. XLVAL xchrneq() { return (chrcompare('#',FALSE)); } /* char/= */
  3265. XLVAL xchrgeq() { return (chrcompare('G',FALSE)); } /* char>= */
  3266. XLVAL xchrgtr() { return (chrcompare('>',FALSE)); } /* char> */
  3267. X
  3268. X/* character comparision functions (case insensitive) */
  3269. XLVAL xchrilss() { return (chrcompare('<',TRUE)); } /* char-lessp */
  3270. XLVAL xchrileq() { return (chrcompare('L',TRUE)); } /* char-not-greaterp */
  3271. XLVAL xchrieql() { return (chrcompare('=',TRUE)); } /* char-equalp */
  3272. XLVAL xchrineq() { return (chrcompare('#',TRUE)); } /* char-not-equalp */
  3273. XLVAL xchrigeq() { return (chrcompare('G',TRUE)); } /* char-not-lessp */
  3274. XLVAL xchrigtr() { return (chrcompare('>',TRUE)); } /* char-greaterp */
  3275. X
  3276. X/* chrcompare - compare characters */
  3277. XLOCAL LVAL chrcompare(fcn,icase)
  3278. X  int fcn,icase;
  3279. X{
  3280. X    int ch1,ch2,icmp;
  3281. X    LVAL arg;
  3282. X    
  3283. X    /* get the characters */
  3284. X    arg = xlgachar(); ch1 = getchcode(arg);
  3285. X
  3286. X    /* convert to lowercase if case insensitive */
  3287. X    if (icase && isupper(ch1))
  3288. X    ch1 = tolower(ch1);
  3289. X
  3290. X    /* handle each remaining argument */
  3291. X    for (icmp = TRUE; icmp && moreargs(); ch1 = ch2) {
  3292. X
  3293. X    /* get the next argument */
  3294. X    arg = xlgachar(); ch2 = getchcode(arg);
  3295. X
  3296. X    /* convert to lowercase if case insensitive */
  3297. X    if (icase && isupper(ch2))
  3298. X        ch2 = tolower(ch2);
  3299. X
  3300. X    /* compare the characters */
  3301. X    switch (fcn) {
  3302. X    case '<':    icmp = (ch1 < ch2); break;
  3303. X    case 'L':    icmp = (ch1 <= ch2); break;
  3304. X    case '=':    icmp = (ch1 == ch2); break;
  3305. X    case '#':    icmp = (ch1 != ch2); break;
  3306. X    case 'G':    icmp = (ch1 >= ch2); break;
  3307. X    case '>':    icmp = (ch1 > ch2); break;
  3308. X    }
  3309. X    }
  3310. X
  3311. X    /* return the result */
  3312. X    return (icmp ? true : NIL);
  3313. X}
  3314. X
  3315. END_OF_FILE
  3316. if test 15062 -ne `wc -c <'src/xlisp/xcore/c/xlstr.c'`; then
  3317.     echo shar: \"'src/xlisp/xcore/c/xlstr.c'\" unpacked with wrong size!
  3318. fi
  3319. # end of 'src/xlisp/xcore/c/xlstr.c'
  3320. fi
  3321. echo shar: End of archive 7 \(of 16\).
  3322. cp /dev/null ark7isdone
  3323. MISSING=""
  3324. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do
  3325.     if test ! -f ark${I}isdone ; then
  3326.     MISSING="${MISSING} ${I}"
  3327.     fi
  3328. done
  3329. if test "${MISSING}" = "" ; then
  3330.     echo You have unpacked all 16 archives.
  3331.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  3332. else
  3333.     echo You still need to unpack the following archives:
  3334.     echo "        " ${MISSING}
  3335. fi
  3336. ##  End of shell archive.
  3337. exit 0
  3338.